Trapped in a Looping Hell!!

goldenvision

Board Regular
Joined
Jan 13, 2004
Messages
234
Any ideas what is wrong with the following code

Code:
Private Sub createMarqueRange()
'specify start sheet
Sheets("Cleaned Sewells (Full File)").Activate
'specify start points
cMRc = 3
currRow = 2
'when to stop
Do Until Cells(currRow, 1) = "x"
If Cells(currRow, 12).Value = cbo_Marques Then
Sheets("Cleaned Sewells (Full File").Range("B" & cMRc, "Q" & cMRc, "S" & cMRc, "T" & cMRc).Copy Sheets("Lookups").Range("C" & currRow)
currRow = currRow + 1
Sheets("Cleaned Sewells (Full File)").Select
Else
'do nothing
End If
cMRc = cMRc + 1
Application.StatusBar = cMRc
Loop
Application.StatusBar = False
End Sub

I think it is reading through a table of data and each time the Marque equals the Marque selected in a combo box it copies the value to a new sheet, increases the row count by one and carries on. Evidently that isn't happening.

Any pointers would be greatly appreciated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

This part of the code got my attention
Code:
Do Until Cells(currRow, 1) = "x"
If Cells(currRow, 12).Value = cbo_Marques Then
...
currRow = currRow + 1

Questions:
Is there any cell with an "x", exactly an "x"
are you sure that the "if" line ever gets true?
else currRow will never get updated

and most important
why did you put
Code:
currRow = currRow + 1

or did you just mix up the variables cuurRow and cMRc

to be honest it is difficult to check out code without data

Did you step through the code using function key F8 and while having a look on your sheet?

kind regards,
Erik
 
Upvote 0

goldenvision

Board Regular
Joined
Jan 13, 2004
Messages
234
Erik,
Thanks for the response.

I ended up changing my entire code to use a For-Next loop and it is now working.

Thanks
David
 
Upvote 0

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
you're WELCOME!!

When I look again at this, couldn't you use a filter to avoid the loop?
filter column 12
copy+paste in one go
done
 
Upvote 0

Forum statistics

Threads
1,191,373
Messages
5,986,271
Members
440,015
Latest member
knijgh

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
Top