Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statements (Excel)

Status
Not open for further replies.

haedyr

Programmer
May 25, 2005
18
US
I wrote this code to try to minimize the amount of paper I throw away when printing. My purpose is to print 1 page of the active statement if the amount is less than $25. If the amount of the download royalty is 0, then I don't want to print out the download summary sheet. I originally tried the if, then, else statements to no avail. I then tried this code and it is printing the same way as the else statement. I'm basically only getting a print out of the statement sheet with an amount due of over $25. (not two like I want). My question is, the code is read over and down like a book. If I have two if statements back to back, does it read the second if statement?

Dim indx As Integer
For indx = 1 To UBound(labels)
Workbooks.Open Filename:=current_pathname & labels(indx).label_name & ".xls", ReadOnly:=True
Sheets("statement").Activate

If labels(indx).amount_due < 25 Then
ActiveSheet.PrintOut
If labels(indx).total_download_royalty = 0 Then
ActiveWorkbook.Close savechanges:=False
End If
End If

If labels(indx).amount_due >= 25 Then
ActiveSheet.PrintOut
ActiveSheet.PrintOut
If labels(indx).total_download_royalty > 0 Then
Sheets("download_summary").Activate
ActiveSheet.PrintOut
ActiveWorkbook.Close savechanges:=False
End If
End If

Next indx

Thanks in advance for your help.
 
your nested if statements will not be read if the initial if statement is false
for exampl id amount_due is >= 25 then it should print 2 pages and if amount_due is >= 25 AND royalty is >0 then "download_summary" will print

Does this answer your question

What happens if amount due <25 ?

Do you want to print if amount_due <25 and download_royalty>0??
 
try this

Dim indx As Integer
For indx = 1 To UBound(labels)
Workbooks.Open Filename:=current_pathname & labels(indx).label_name & ".xls", ReadOnly:=True
Sheets("statement").Activate

If labels(indx).amount_due < 25 Then
ActiveSheet.PrintOut
else
ActiveSheet.PrintOut copies:=2
end if

If labels(indx).total_download_royalty > 0 Then
Sheets("download_summary").Activate
ActiveSheet.PrintOut
End If
ActiveWorkbook.Close savechanges:=False

Next indx


this should work from my understand of what you want.
Shoule print 1 copy of the statement if <$25 and 2 copies above. also will print 1 copy of the summary if royalty is greater than 0

Chris
 
ck1999 - thank you for your tip. I did originally try the code you suggested to no avail. When using this code, statements that are < 25 only print once (and the total download = 0). That seems to work fine. But, when it's > 25 only one copy prints out. and if the total download > 0 the download sheet doesn't print.

I have the amount_due variable defined as single. I don't know if that is a problem or not.

This code makes the most sense so I'm not sure why it's acting this way. I will say, however, that running macros on my pc that have error trapping don't seem to work. I'm wondering if there's something up with my excel options??
 
I wanted to tell you I figured it out. I needed to load the value of the cells amount_due and total_download_royalty. Therefore, I used

if range("amount_due").value > 25 then


Thanks for all your help....

Haedyr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top