Hi There,
Thank you in advance for taking the time to read this. I've tried to search for the answer but to no avail so I'm hoping some very kind person will be able to help put me out of my misery.
I'm trying to search for a specific term within a column of a worksheet, if that is found, execute a copy and paste (in the row above), then move and search for the next term up to 1,000 rows.
The frustrating part is that it executed perfectly once, then is giving me a 1004 error and I can't figure out why the error is occurring.
I appreciate any help I can get on this.
Thank you in advance for taking the time to read this. I've tried to search for the answer but to no avail so I'm hoping some very kind person will be able to help put me out of my misery.
I'm trying to search for a specific term within a column of a worksheet, if that is found, execute a copy and paste (in the row above), then move and search for the next term up to 1,000 rows.
The frustrating part is that it executed perfectly once, then is giving me a 1004 error and I can't figure out why the error is occurring.
I appreciate any help I can get on this.
VBA Code:
Sub NewMonthAlt()
Dim i As Integer
Dim startRange As Integer, endRange As Integer
Dim rng As Range
Dim searchWord As String
Dim rngPaste As Range
Dim startpaste As Integer
searchWord = "XX"
With Sheets("Models")
For i = 1 To .Cells(Rows.Count, 1000).End(xlUp).Row
If .Range("C" & i) = searchWord Then 'Here it notes the row where we first find the search word
startRange = i
Do Until .Range("C" & i) <> searchWord
i = i + 1 'Here it notes the first time it stops being that search word
startpaste = i - 2
Loop
endRange = i - 1 'Backtracking by 1 because it does it once too many times
Exit For
End If
Next
'Select range to copy
Set rng = ActiveSheet.Range("D" & startRange & ":O" & endRange)
Set rngPaste = ActiveSheet.Range("D" & startpaste & ":O" & startpaste)
rng.Copy
rngPaste.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False 'Paste it to the address set
End With
End Sub