Results 1 to 3 of 3

Thread: If statment loop

  1. #1

    If statment loop



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

    Hello.

    How i can make that go till lastrow.


    Sub loop()
    If Range("B1") = 0 Then
    Range("C1").Value = Range("A1")
    ElseIf Range("B2") = 0 Then
    Range("C2").Value = Range("A2")
    ElseIf Range("B3") = 0 Then
    Range("C3").Value = Range("A3")
    ElseIf Range("B4") = 0 Then
    Range("C4").Value = Range("A4")
    Elseif .....................
    end Sub


    I have lots more then 4 rows.


    Ty.

  2. #2
    Seeker AnalystCave's Avatar
    Join Date
    Dec 2015
    Location
    Poland
    Posts
    11
    Articles
    0
    Doesn't seem sensible. What are you trying to achieve?

  3. #3

    Hello

    Hello Ty,

    I presume this is what you want to do.

    Sub copyifValueIsZero() For i = 1 To 500
    If ThisWorkbook.Sheets("Sheet1").cells(i, 2).value = 0 Then
    ThisWorkbook.Sheets("Sheet1").cells(i, 1) = ThisWorkbook.Sheets("Sheet1").cells(i, 3).value
    End If
    Next i
    End Sub


    Note: Change 500 to the number of rows you want. For example if you want the code to process until 10000 rows then change 500 to 10000.
    Job Done.

    Cheers
    MDC




    Quote Originally Posted by paltser View Post
    Hello.

    How i can make that go till lastrow.


    Sub loop()
    If Range("B1") = 0 Then
    Range("C1").Value = Range("A1")
    ElseIf Range("B2") = 0 Then
    Range("C2").Value = Range("A2")
    ElseIf Range("B3") = 0 Then
    Range("C3").Value = Range("A3")
    ElseIf Range("B4") = 0 Then
    Range("C4").Value = Range("A4")
    Elseif .....................
    end Sub


    I have lots more then 4 rows.


    Ty.

Posting Permissions

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