Reputation: 13
I am stuck again..
I have used a macro for a long time, but now I need to add a feature to the macro.
Sub InsRow()
Dim c
Application.ScreenUpdating = False
For Each c In Selection
If c.Offset(0, -1) <> c And c.Offset(0, -1) <> "" Then
c.Offset(0, 1).Insert shift:=xlDown
c.Insert Shift:=xlDown
End If
Next c
Application.ScreenUpdating = True
End Sub
This macro looks if the value in column B is the same as in column A. When this is not the case, it shifts the cells of column B and C down, till they sync again. However, I want column d till.... also to shift down. How can I add this feature to the macro?
Thanks in advance.
Upvotes: 0
Views: 147
Reputation: 3279
Try something like this:
Sub InsRow()
Dim c
Application.ScreenUpdating = False
For Each c In Selection
If c.Offset(0, -1) <> c And c.Offset(0, -1) <> "" Then
'Change the "D" to whichever column you want to shift down.
Range(cells(c.Row,"B"),cells(c.Row,"D")).Insert shift:=xlDown
c.Insert Shift:=xlDown
End If
Next c
Application.ScreenUpdating = True
End Sub
The above sub will shift down for all columns from B to whichever column you specify. Currently it will shift columns B, C, and D down.
Upvotes: 1