Hi, please can you help me with the following.
I have worked on a bit of VBA code that loops through and array to change the values of the cells to 1 until last empty cell for all columns in the array.
However its not working as intended. Only if I change the value of J to any of the columns ("A","B",etc..) does work but only changes the values for the specified column.
Can you help with what needs to be changed for the code to loop through all columns and rows? Much thanks.
I have worked on a bit of VBA code that loops through and array to change the values of the cells to 1 until last empty cell for all columns in the array.
However its not working as intended. Only if I change the value of J to any of the columns ("A","B",etc..) does work but only changes the values for the specified column.
Can you help with what needs to be changed for the code to loop through all columns and rows? Much thanks.
VBA Code:
Sub Loop2()
Dim LastRow As Long, i As Long, j As Long, ws As Worksheet
Set ws = Sheets("Sheet1")
LastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
With ws
For j = 1 To LastCol
For i = 1 To LastRow
.Range(j & i) = 1
Next i
Next j
End With
End Sub
Last edited by a moderator: