SOLVED

Macro to input values for lastcol with regards to a specific row

Regular Contributor

Would like to seek advise for a macro to input values in the next column of lastcol; ie lastcol.offset(0, 1).

 

For example if there is a value in A1, when the macro executed, the value will be populated in A2.

 

Currently, the code below would populate data in cell B32. The column is correct but the row no is incorrect

Dim lastCol As Long
Dim ws as Worksheet

Set ws = Sheet4
lastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1

ws.Range("A3" & lastCol).Offset(0, 1).value = "Yes"

 

Thanks for the help in advance!

 

4 Replies
best response confirmed by Hans Vogelaar (MVP)
Solution

@hrh_dash If you want to add data to right after last column of a specific row then try-

Sub AddToLastCol()
Dim lastCol As Long
Dim ws As Worksheet

    Set ws = Sheet4
    lastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
    ws.Cells(1, lastCol) = "Yes"

End Sub
Thanks! Much appreciated!
If it helps then please mark the answer as solved (tick mark it).
my apologies i overlooked on the tick portion.