I have a spreadsheet that will have multiple header-style rows in it. I want to copy the row beneath each header using a script. I currently have this from a 3 year old StackOverflow answer:
Private Sub CommandButton4_Click()
Dim i As Range
For Each i In Sheet1.Range("A1:A1000")
Select Case i.Value
Case "HERE"
Sheet3.Range("A" & Sheet3.Rows.Count).End(xlUp).Offset(1, 0).EntireRow.Value = i.EntireRow.Value
Case Else
End Select
Next i
End Sub
This works, except it copies the header itself (HERE
), and not the data beneath it. I'm still new to VBA, so I'm not sure how to adjust this. I've tried something like Dim j As Integer
, then j = i + 1
and j.EntireRow
etc, but that doesn't work because i
is Range
and not Integer
. I don't know enough about VBA yet to get this working.
Any advice? Thank you!
EDIT: In addition to the scenario when I copy just the first row beneath the header, can I also modify this to copy x
rows beneath the header? For example, once it finds the header, copy the next three rows. Thanks again!