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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

shaneherron

Board Regular
Joined
Nov 3, 2009
Messages
51
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
 

Zac

Well-known Member
Joined
Feb 20, 2002
Messages
796
I'LL GIVE IT A SHOT BUT i MAY HAVE TO COME BACK TO YOU.....
 

Zac

Well-known Member
Joined
Feb 20, 2002
Messages
796
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?
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
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.
 

shaneherron

Board Regular
Joined
Nov 3, 2009
Messages
51
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,361
Messages
5,635,812
Members
416,884
Latest member
leeshjay

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