0

Hi I have an excel macro question in VBA. I have this code. I want it to go down each cell in row C and run the same if statement instead of just depending on cell C2. I want it to continue to C3, C4, C5, all the way till the end of the sheet. Can anyone help me solve this?

Sub Macro1()



Dim lngLastRow As Long
    lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row

    If IsEmpty(Range("C2")) Then
        Range("E2:E" & lngLastRow).Formula = "=B2 & ""_"" & C2"
    Else
    Range("E2:E" & lngLastRow).Formula = "=B2"
    End If
    End Sub

Edited by tommyneedshelp

2
Contributors
2
Replies
10
Views
1 Year
Discussion Span
Last Post by tommyneedshelp
1

To have you on the path to a solution: Make a Do While loop with your found last row!
use a Counter as variable for creating your range in "Cn" and match where you are.
something like:
Dim MyRowCounter as Integer = 2
Do While MyRowCounter =< LngLastRow
concatenate your Range
do your If
MyRowCounter = MyRowCounter + 1
loop

btw. a long is big I think an integer is enough for a counter in Excel! (lngLastRow)
Succces, I hope my help gets you further on your way..
Rene

Edited by Rene vK

Votes + Comments
Good advice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.