ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA IF QUESTION (https://www.excelbanter.com/excel-programming/409060-vba-if-question.html)

Hamed parhizkar

VBA IF QUESTION
 
I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than zero.

Please help.

joel

VBA IF QUESTION
 
when you have code on the same line as the THEN it is the only part of the
code that is checked



If Range("C28") 0 Then _
Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
end if

"Hamed parhizkar" wrote:

I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than zero.

Please help.


joel

VBA IF QUESTION
 
Don't put the continuation line after the then. I caught the mistake just
when I press the reply button as the window was closing.

from
then _
to
then


"Hamed parhizkar" wrote:

I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than zero.

Please help.


GerryGerry

VBA IF QUESTION
 
Change to following:-


If Range("C28") 0 Then
Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
end if


"Hamed parhizkar" wrote in
message ...
I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than
zero.

Please help.




Hamed parhizkar

VBA IF QUESTION
 
So what is the formula suppose to look like, I dont have a _ in there?

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True



"Joel" wrote:

Don't put the continuation line after the then. I caught the mistake just
when I press the reply button as the window was closing.

from
then _
to
then


"Hamed parhizkar" wrote:

I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than zero.

Please help.


Don Guillett

VBA IF QUESTION
 
Sub printif()
If Range("c28") 0 Then Range("a23:d34").Printout 'Preview
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Hamed parhizkar" wrote in
message ...
I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What am I
doing wrong. I only need it to print the range if c28 is greater than
zero.

Please help.



Rick Rothstein \(MVP - VB\)[_1676_]

VBA IF QUESTION
 
It should look like this...

If Range("C28") 0 Then
Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

Whenever you have multiple statements that, as a group, will only be
executed for a given logical condition, you put all the multiple statements
between an If-Then statement (with nothing following the Then) and an End If
statement.

Rick


"Hamed parhizkar" wrote in
message ...
So what is the formula suppose to look like, I dont have a _ in there?

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True



"Joel" wrote:

Don't put the continuation line after the then. I caught the mistake
just
when I press the reply button as the window was closing.

from
then _
to
then


"Hamed parhizkar" wrote:

I have this formula in vba:

If Range("C28") 0 Then Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

It works fine and prints but it prints even if the cell is zero. What
am I
doing wrong. I only need it to print the range if c28 is greater than
zero.

Please help.




All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com