Macro help needed.

Zac

Well-known Member
Joined
Feb 20, 2002
Messages
796
Need some help with a macro problem.

In B1 I have a COUNTA formula which gives me the number of items remaining after a task is performed. It was suggested I do this by a board member which is a great idea. My problem is I don't know how to write the code. So if anyone can help I would greatly appreciate it.

At some point in my routine I will run out of data to process.

I use the Data filter in Col "P".

When the Value in B1 = 0, end the program (GOTO End Sub ??) , if not continue. How do I write the code for this step?

Thanks for your help,
Zac
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Zac,
Use a Do-Loop statement. Here is an example, adapt it for your needs.

Code:
Do Until Sheet1.Range("b1").Value = 0
    'Your code goes here
Loop
 
Upvote 0
Do Until Sheet1.Range("b1").Value = 0
'Your code goes here
Loop

If I get a value of 0, how do I skip to the end of the program.
Does it automatically go to END SUB?
 
Upvote 0
In the code you have there, it will go to Loop and then continue down to the next line, as opposed to going back to the Do statement again.
 
Upvote 0
Zac, when you get a 0 value it exits the loop. It will continue on the line after "Loop" automatically. If you want it to go to end sub and loop isn't the end then you will need to use a GOTO and place a label at the end of the sub.
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,208
Members
448,951
Latest member
jennlynn

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