Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default 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.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 09:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"