Hello all,
Recently, y’all provided me with a macro to add unique values above in non blank row. The VBA works perfectly but I would like to be able to use that VBA on any sheet.
Right now, I can only use it on “Sheet1.” Can somebody change the VBA so that I can run it on whatever sheet I am on?
The code is below. Thank you.
Recently, y’all provided me with a macro to add unique values above in non blank row. The VBA works perfectly but I would like to be able to use that VBA on any sheet.
Right now, I can only use it on “Sheet1.” Can somebody change the VBA so that I can run it on whatever sheet I am on?
The code is below. Thank you.
VBA Code:
Sub DeleteAndAdd()
Dim r As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, "C").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "C") = 0 Then
Rows(r).Delete
End If
Next r
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step by - 1
a = Worksheets("Sheet1").Cells(i, 3).Value
For j = 1 To a
Worksheets("Sheet1").Rows(i).Select
Selection.Insert Shift:=xlDown
Next
Next
Worksheets("Sheet1").Cells(1, 1).Select
End Sub
Last edited by a moderator: