Brain Teaser

spcalan

Well-known Member
Joined
Jun 4, 2008
Messages
1,247
Here is my question.

I have a worksheet with 12 columns ( L ) with data.

I am wanting to find each cell in column L that starts with "Q".
It will always start with "Q" and be either "Q001" or "Q002" or "Q003" or "Q004".

I want to be able to run a VBA code that will capture it along with the Column A/Column B/Column L and copy/paste into another sheet.

Any ideas?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It seems to me that the code should go like this:

Find cell in Col L that starts with "Q".
Copy ColA/ColB/ColC/ColL
Paste into Sheet 2.
 
Upvote 0
Something like this should work:

Code:
sub copyabl()
dim LR2 as long
For i = 1 to cells(rows.count,"L").end(xlup).row
if left(cells(i,"L").value,1)="Q" then
LR2 = Sheets("Sheet2").cells(rows.count,1).end(xlup).row +1
Sheets("Sheet2").range("A" & lr2 & ":B" & lr2).value = range("A" & i & ":B" & i).value
Sheets("Sheet2").range("C" & lr2).value = range("L" & i).value
end if
next i
end sub
This is untested. Hope that helps.
 
Upvote 0
Hi,

try this manually: should not take more than 1 minute
autofilter column L
custom criterion: "starts with"
then write Q

hide the columns C to K
copy and paste

If this works for you (for me it does) and you need this often, then you can record a macro while doing this. Using autofilter will make your code much quicker than row-by-row approach.

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

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