Forum Discussion
ushbar
Oct 28, 2020Copper Contributor
Select every N-th row and replace column values
Hi, I'm new to VBA and macro so I need help with a script/code that can select every 18th-21th row and replace column "I" with the following values: Paranøtter Pekannøtter Pistasjnøtt...
- Oct 28, 2020
Sub EditRows() Dim r As Long Dim m As Long Application.ScreenUpdating = False m = Range("A" & Rows.Count).End(xlUp).Row For r = 19 To m Step 21 Range("I" & r).Value = "Paranøtter" Range("I" & r + 1).Value = "Pekannøtter" Range("I" & r + 2).Value = "Pistasjnøtter" Range("I" & r + 3).Value = "Valnøtter" Range("L" & r).Resize(4, 4).ClearContents Next r Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
HansVogelaar
Oct 29, 2020MVP
Sub MovePeanøtter()
Dim r As Long
Dim m As Long
Application.ScreenUpdating = False
m = Range("A" & Rows.Count).End(xlUp).Row
For r = 6 To m Step 21
Range("A" & r).EntireRow.Cut
Range("A" & r + 17).EntireRow.Insert
Next r
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Subushbar
Oct 30, 2020Copper Contributor
thanks a lot! 🙂