Results 1 to 4 of 4

Thread: how to run 2 VBA codes on 1 sheet

  1. #1
    Neophyte hh2021's Avatar
    Join Date
    Jun 2021
    Posts
    1
    Articles
    0
    Excel Version
    2010

    how to run 2 VBA codes on 1 sheet



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I tried to run 2 simple codes they worked separately. When I ran them together the data was interfered with each other. Please help. Thank you :-)

    Module1:
    Sub calc1()
    Range("$D$2").Value = Range("$D$2").Value + Range("$C$2").Value
    End Sub

    Sub calc2()
    Range("$D$10").Value = Range("$D$10").Value + Range("$C$10").Value
    End Sub

    Sheet1:
    Private Sub Worksheet_Calculate()
    Call calc1
    Call calc2
    End Sub

    I tried Range("D2:D10").Value = Range("D2:D10").Value + Range("C2:C10").Value not working any idea?
    Last edited by p45cal; 2021-08-26 at 09:22 PM. Reason: typoerror

  2. #2
    Seeker jolivanes's Avatar
    Join Date
    May 2020
    Posts
    19
    Articles
    0
    Excel Version
    2007 & 2016
    Try
    Code:
    Range("D210").Value = Range("D210").Value + WorksheetFunction.Sum(Range("C2:C10"))

  3. #3
    Conjurer Logit's Avatar
    Join Date
    Nov 2016
    Posts
    303
    Articles
    0
    Excel Version
    2007
    This works here :

    Code:
    Sub RunBoth()    Range("$D$2").Value = Range("$D$2").Value + Range("$C$2").Value
        Range("$D$10").Value = Range("$D$10").Value + Range("$C$10").Value
    End Sub

  4. #4
    Seeker jolivanes's Avatar
    Join Date
    May 2020
    Posts
    19
    Articles
    0
    Excel Version
    2007 & 2016
    Code:
    Sub Or_Do_You_Mean_So()
    Dim i As Long
        For i = 2 To 10
            Cells(i, 4).Value = Cells(i, 4).Value + Cells(i, 3).Value
        Next i
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •