Hello!
I have the following problem with a code:
I have 2 sheets, named "Sheet1" and "Summary"
In the "Sheet1", I have data like:
A
1 FCR-E00001
2 something
3 something
4 something
5 FCR-F38346
6 something
7 something
8 FCR-Y02934
etc
The letters and numbers after the "FCR-" are not constant, but the first part stays the same.
What I need to do is, look for example "FCR-F38346" and the macro would copy that row and all the rows related to it (in this case A5, A6 and A7). I have made a code as far as finding and copying when I give the code both entries, like FCR-F38346 and FCR-Y02934 manually.
But I need to implement an InputBox to set the first value to be searched, and it needs to loop until it finds the NEXT "FCR-" in the column.
For example, if I search for FCR-E00001, it loops until it finds FCR-F38346, and copies all the rows between to the sheet "Summary".
I didn't manage to implement the InputBox, and I couldn't make the loop to stop at the next "FCR-" line.
Here is what I have so far:
Thank you for your assistance!
-Grazier
I have the following problem with a code:
I have 2 sheets, named "Sheet1" and "Summary"
In the "Sheet1", I have data like:
A
1 FCR-E00001
2 something
3 something
4 something
5 FCR-F38346
6 something
7 something
8 FCR-Y02934
etc
The letters and numbers after the "FCR-" are not constant, but the first part stays the same.
What I need to do is, look for example "FCR-F38346" and the macro would copy that row and all the rows related to it (in this case A5, A6 and A7). I have made a code as far as finding and copying when I give the code both entries, like FCR-F38346 and FCR-Y02934 manually.
But I need to implement an InputBox to set the first value to be searched, and it needs to loop until it finds the NEXT "FCR-" in the column.
For example, if I search for FCR-E00001, it loops until it finds FCR-F38346, and copies all the rows between to the sheet "Summary".
I didn't manage to implement the InputBox, and I couldn't make the loop to stop at the next "FCR-" line.
Here is what I have so far:
Code:
Sub Search()
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 = "FCR-E00001" Then 'Needs to be changed to variant
startrow = rownum
End If
rownum = rownum + 1
If (rownum > lastrow) Then Exit For
Loop Until .Cells(rownum, 1).Value <> "FCR" 'Needs to look for the next "FCR" in line and stop
endrow = rownum - 1
rownum = rownum + 1
Worksheets("Sheet1").Range(startrow & ":" & endrow).Copy
Sheets("Summary").Select
Range("A1").Select
ActiveSheet.Paste
Next rownum
End With
End Sub
Thank you for your assistance!
-Grazier