Help with look up and row paste

jedibrown

Board Regular
Joined
Oct 17, 2011
Messages
136
Hi,

Basically, I am creating some data and I am a bit stuck.

I would like to say:

If any cells in column c have the word "Giant" in it (there will be a sentance in each cell but I would like it to pick out the specific word) - Then please paste the whole line into sheet 2.

Is this possible?

Many thanks
 
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Not IsError(Range("C" & i)) Then
        If InStr(Range("C" & i).Value, "giant") > 0 Then Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next i
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
No I don't - I have deleted column a and changed the code to look at column "b".

Works better - now 12 are being pasted but still should be 36
 
Upvote 0
Perhaps

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Not IsError(Range("B" & i)) Then
        If InStr(LCase(Range("B" & i).Value), "giant") > 0 Then Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next i
End Sub
 
Upvote 0
Yes!!! It works!!! Thank you so much for all of your help - It is VERY much appreciated!

Just 2 last things - How do I now attach it to a control button?

Also, is there any way to add another variable to it? So it looks for "giant" and "large".

Sorry to be a pain - I bet you wish you hadn't started helping me now!
 
Upvote 0
Try

Code:
Private Sub CommandButton1_Click()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Not IsError(Range("B" & i)) Then
        If InStr(LCase(Range("B" & i).Value), "giant") > 0 Or InStr(LCase(Range("B" & i).Value), "large") > 0 Then Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next i
End Sub
 
Upvote 0
Hmmm, would it be because there is an & in the variable (you may have guessed that giant and large are not the actual things I'm looking for but I am testing before I build).

I am actually looking for P&L. When I change the first variable to P&L and the second to breach - nothing comes up at all yet there are 4 cells with P&L in them.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top