As stated above, this code finds all values of X and copies them to another sheet. Standard and straightforward. But I would like to
ask Excel to use the FIND method not only to find X but also copy the 4 values in the cell rows above(X.offset(-4,0?)
to another sheet for every value of X found:.
I tried to make this as eay as possible to understand. Not really difficult, just knowing how to ddjust this code
to just copy 4 cell value rows above X to another sheet for each value of X found with a row space between each set of 4 values for X
I worked on this several hours without success. Would really appreciate anyone's help.
Thanks
cr
ask Excel to use the FIND method not only to find X but also copy the 4 values in the cell rows above(X.offset(-4,0?)
to another sheet for every value of X found:.
Code:
Private Sub cmdFIND_Click()
Sheets("ALTVERSIONS").UsedRange.ClearContents
Dim lastrow, lastrow2 As Integer, X As String, c As Range, rw As Long, firstAddress As Variant, rowno As Variant, RownoA As Variant
X = Me.TextBox1.Value
With Worksheets("Sheet2").Range("E1:E31103")
Set c = .FIND(X, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
rw = 1
firstAddress = c.Address
Do
Worksheets("Sheet2").Select
c.Select
Range(Cells(c.Row, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("ALTVERSIONS").Range("B" & rw)
rw = rw + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
lastrow = Sheets("ALTVERSIONS").Range("B" & rows.count).End(xlUp).Row
If lastrow = 1 Then
Range(Cells(c.Row + 7, 2), Cells(c.Row, 7)).Copy Destination:=Sheets("ALTVERSIONS").Range("B" & rw)
Else
End If
Else
MsgBox "value not found"
End If
End With
End Sub
I tried to make this as eay as possible to understand. Not really difficult, just knowing how to ddjust this code
to just copy 4 cell value rows above X to another sheet for each value of X found with a row space between each set of 4 values for X
I worked on this several hours without success. Would really appreciate anyone's help.
Thanks
cr