dcsimg
Results 1 to 4 of 4

Thread: How to apply the same code to all rows in VBA, Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    2

    Question How to apply the same code to all rows in VBA, Excel

    Simple question, I'm new to VBA - how do I apply the following code to all rows (except the first two) without manually writing it for every single one?

    Thanks!!


    Code:
    Sub DueUpdate()
    '
    ' DueUpdate Macro
    '
     
    '
    If Range("I3").Value <> Completed Then Range("F3").Copy Range("G3")
    If Range("I4").Value <> Completed Then Range("F4").Copy Range("G4")
    If Range("I5").Value <> Completed Then Range("F5").Copy Range("G5")
    If Range("I6").Value <> Completed Then Range("F6").Copy Range("G6")
    If Range("I7").Value <> Completed Then Range("F7").Copy Range("G7")
    If Range("I8").Value <> Completed Then Range("F8").Copy Range("G8")
    If Range("I9").Value <> Completed Then Range("F9").Copy Range("G9")
    If Not Range("A1").Value <> Tracker Then
    End If
    End Sub

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,122

    Re: How to apply the same code to all rows in VBA, Excel

    Code:
    Sub DueUpdate()
    Dim i As Long
    For i=3 To 9
    If Range("I" & i).Value<> Completed Then Range("F" & i).Copy Range ("G" & i)
    Next
    End Sub
    I do hope that "Completed" is a Function.....
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2019
    Posts
    2

    Re: How to apply the same code to all rows in VBA, Excel

    No completed is not a function, it is a condition. It's looking if the cell contains the word completed.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,122

    Re: How to apply the same code to all rows in VBA, Excel

    Then you have to put in Parantheses
    If Range.Value<>"Completed" Then...
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width