trying to extract data

spcalan

Well-known Member
Joined
Jun 4, 2008
Messages
1,247
here is my code

Sub D_Extract()
x = 1
y = 2

'Find Last Row in Column A
lr = Sheets("sheet1").Cells(Rows.Count, "J").End(xlUp).Row
MsgBox lr

'Extracts Product Code / Description / Lot# / Charge Code

Do Until x = lr
Do Until Left(Sheets("sheet1").Cells(x, 11), 1) = "Q"
x = x + 1
Loop

pcode = (Sheets("sheet1").Cells(x, 3))
desc = (Sheets("sheet1").Cells(x, 4))
lot# = (Sheets("sheet1").Cells(x + 1, 9))
chcode = (Sheets("sheet1").Cells(x, 11))

'Paste Extracted Data in "Data" Sheet
Sheets("data").Cells(y, 1) = pcode
Sheets("data").Cells(y, 2) = desc
Sheets("data").Cells(y, 3) = lot#
Sheets("data").Cells(y, 4) = chcode

x = x + 1
y = y + 1
Loop

End Sub

The code works perfect, but times out once it gets to 65,536.
But why isnt it stopping at the value of lr( last row )?? which is 2202 rows??
I have lr defined, and do until x=lr, but still dont work.

Ideas?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Haven't really read the code to see what exactly it's doing, but it looks like X may incriment by more than 1 for each loop, so it's possible x will never = lr..

change
Do Until x = lr
to
Do Until x >= lr

Does that work?
 
Upvote 0
Thank you.

Works perfect now, and stops when it supposed to.

Thanks again.


( just another tip I will be adding to the master list of vba code that works )
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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