Hi,
I am quite new to VBA. I have stolen a little piece of code from another website and the code works very well with a little alteration. The code searches for a value inside a given cell. If it finds a match, it will then copy and paste the whole row into another sheet. Here is the code
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 1
LSearchRow = 1
'Start copying data to row 3 in Sheet2 (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column B = "Voids", copy entire row to Voids
If Range("B" & CStr(LSearchRow)).Value = "Voids" Then
'Select row in All alarms to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("Voids").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets("All Alarms").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A1").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred you tit, sort it out."
End Sub
What I wanted to do is alter the code marked in red to, rather then = the value "voids". I wanted to search to see if the cell contained the same word. If it does then do exactly the same as I am doing at the moment.
Thank you in advance for your help
Ashley
Bookmarks