Hello I am trying to find two key words in a data dump of text that has the words reoccurring. I am wanting to copy and past all the text on the rows between these key words and paste the results to a new row on a sheet named "result".
The below code does the most part of what I am trying to do but it overwrites each iteration of the loop over the top of the previous found result on the new sheet. I just need the code to add each iteration on a new line of the sheet named "Result"
I am new to VBA and not sure what would do it. Any help is very much appreciated!
The below code does the most part of what I am trying to do but it overwrites each iteration of the loop over the top of the previous found result on the new sheet. I just need the code to add each iteration on a new line of the sheet named "Result"
I am new to VBA and not sure what would do it. Any help is very much appreciated!
VBA Code:
Sub Test()
Dim rownum As Long
Dim colnum As Long
Dim startrow As Long
Dim endrow As Long
Dim lastrow As Long
rownum = 1
colnum = 1
lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row
With ActiveWorkbook.Worksheets("Sheet1").Range("a1:a" & lastrow)
For rownum = 1 To lastrow
Do
If .Cells(rownum, 1).Value = "WordA" Then
startrow = rownum
End If
rownum = rownum + 1
If (rownum > lastrow) Then Exit For
Loop Until .Cells(rownum, 1).Value = "WordB"
endrow = rownum
rownum = rownum + 1
Worksheets("Sheet1").Range(startrow & ":" & endrow).Copy
Sheets("Result").Select
Range("A1").Select
ActiveSheet.Paste
Next rownum
End With
End Sub