You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
I have to search a column for "BP1" and/or "BP2". Once I find it, I must copy that entire row ... then proceed to paste that row into a separate worksheet. I must do this for all instances of "BP1" and/or "BP2". Here is what I have so far... but it is not working..
Sub Copy_BP_Data()
x = 0
For Each cl In Sheets("Lookup").Range("F4:F500") 'look in column F
If cl.Value = "" Then
x = x + 1
End If
If cl.Value = "BP1" Then 'Search for "BP1"
d = 5
j = 3
ActiveCell.EntireRow.Copy Sheets("Bipole1").Rows(j) 'Paste into other ws
End If
j = j + 1
d = d + 1
If cl.Value = "BP2" Then
h = 5
i = 3
ActiveCell.EntireRow.Copy Sheets("Bipole2").Rows(i)
h = h + 1
i = i + 1
If cl.Value = "BP1/2" Then
k = 5
l = 3
ActiveCell.EntireRow.Copy Sheets("Bipole1").Rows(k)
ActiveCell.EntireRow.Copy Sheets("Bipole2").Rows(k)
End If
k = k + 1
l = l + 1
Since you are basically searching for couple of words and copying the text, I would recommend you use the AutoFilter and copy the visible content to the other sheet. This will be pretty fast for your requirement