Link to home
Start Free TrialLog in
Avatar of rsernowski
rsernowskiFlag for Afghanistan

asked on

add txt to last cell

Hello ,
I am looking for some Excel VBA code to add in a conditional txt message in  an excel macro. the row count will always change so the words cannot be in the  same row , but it can always be in Col B  

it would read something  like

If cell ( 2,1) = "USD"
add to the last row  in Column B
"Please Do FX"

thanks
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

rsernowski,

You can find the last row of B Column then using...

dim lrow as long
lrow=cells(Cells.rows.count,"B").END(Xlup).row
cells(lrow,1).value="USD"

Open in new window


You can tweak your code accordingly...

Saurabh...
Avatar of Professor J
Professor J

Sub test()

lastR = Cells(Rows.Count, 2).End(xlUp).Row

For i = 2 To lastR

If Cells(i, 1).Value = "USD" Then
 Cells(i, 2).Value = "Please Do FX"
 End If
Next i
End Sub

Open in new window

Avatar of rsernowski

ASKER

Thanks Saurabh

thanks
so I can find the last row, but I need a if statement ? the cell  F2 can either be USD or CAD. so it if it USD , then I need to add statement to the last row saying . "Please Do FX"
it looks like you are typing in USD

dim lrow as long
lrow=cells(Cells.rows.count,"B").END(Xlup).row
if cell f2 = USD
cells(lrow,1).value="Please do FX"

?
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for quick Response! It worked
Have a good day