Macro ignores IF statement that refers to cell value

J

Joe

I have a macro that loops thru about 50 locations and gathers information.
In the interest of saving paper for a location with no data I don't want to
print the locations report. I have a cell that counts the values on the
sheet and only want to print if the count is greater than 0.

I have the following in the macro, where INVCOUNT is the range name that
counts cells with data and PRINTFORM is the macro that will print.

If INVCOUNT > 0 Then PRINTFORM

The statement never seems to execute the PRINTFORM macro. However, if i
just do PRINTFORM it will print all locations.

What do I do?
 
P

Patrick Molloy

ensure that you have
OPTION EXPLICIT
at the very top of your code sheet.
That will force you to specifically DIM all variables and ensures that VBA
won't simply treat INVCOUNT as a local variable. IN this case, it will
coerce to double with a zero value... hence the IF will never have a TRUE
value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top