Hi Experts,
I am newbie to Excel VBA. So I request your help in a VBA script.
I am actually having lot of clients in column "C"and their details in the same row in a sheet. I have a task to split there clients, industry wise and put it into separate sheets.
For example:Telecom client name in column "c". This has to be extracted and put into a new sheet "telecom" and copy all the details of tht client in the new sheet. This way i have multiple clients in different rows.Below is the script I have written a for one client, but muliple clients script is required. Please help.
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 2
LSearchRow = 1
'Start copying data to row 2 in Sheet3 (row counter variable)
LCopyToRow = 1
While Len(Range("D" & CStr(LSearchRow)).Value) > 0
'If value in column D = "AIRCEL", copy entire row to Sheet2
If Range("D" & CStr(LSearchRow)).Value = "AIRCEL" Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet3in next row
Sheets("Sheet3").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("Sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A1
Application.CutCopyMode = False
Range("A1").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
Bookmarks