Need help writing Excel Macro to set printing

roc17

Member
Dec 26, 2003
112
0
0
I'll try to explain here w/o too much ramble:

I have a worksheet that contains several rows and columns. For simplicity sake, let's say that column A is Fruit, column B is quantity, column C is unit price and column D is total ($$). Now.....assume 36 rows each representing a different type of fruit. If I only wanted to print the rows for those types of fruit that were ultimately purchased vs. the entire sheet each time regardless of how many were chosen - How would I write a macro to achieve this and where would I install/store the macro?

Told you I was novice.....

Much appreciated.....

 

PowerEngineer

Diamond Member
Oct 22, 2001
3,558
736
136
Excel is so flexible that there are almost always many ways to accomplish the same thing. If I were trying to do what you describe, I would not use a macro. Instead I would set up a second sheet on which I would have cell formulas which only copied over those rows from sheet one that had non-zero quantities. You could then just print out this second sheet. Unfortunately, the formulas may be hard to grasp if you're an Excel novice.

Let's say that your list of 100 fruits starting in row 5. I'd start by adding a (hidden) column E formula like this (for cell E8):

=IF($B8>0,MAX(E$1:E7)+1,"")

Copy this formula in column E for rows 5 through 104. You'll see that the result is a counting of the rows that you want printed. In cell F3 put the formula:

=MAX(E5:E104)

On sheet 2, put the numbers 1 through 100 in column A, rows 5 through 104. In column B put a formula like this (for cell B8):

=IF('Sheet1'!$F$3>=$A8,MATCH($A8,'Sheet1'!$E:$E,0),"")

You should see that column B is a list of the row numbers from sheet 1 that have non-zero quantities. Now the rest is easy. In column C put in a formula like this (for cell C8):

=IF($B8>0,INDEX('Sheet1'!A:A,$B8,1),"")

Copy this formula across columns C through F and rows 5 through 104. This should give you the list to print.

One more thing; define the print area on sheet 2 as C5:F104 so that the A and B columns don't show.

I use these kinds of tricks all the time, but I did not actually test these formulas out and therefore apologize for any typos (or brain freezes) you find.

Good luck.
 

KLin

Lifer
Feb 29, 2000
29,501
126
106
Put the data in access. Query the data you want. Print it. Much easier than managing in excel.
 

roc17

Member
Dec 26, 2003
112
0
0
Power Engineer....thanks for the all the advice...but I couldn't get it to fly.

I copied the sheet from the workbook and emailed to a friend who added some VBA code to it and it really works well. He appears to have added 2 buttons off to the right of the data area (if a row is chosen from the list via input into one of the cells, either number of units or price...not sure...and the 'Print' button is chosen, it segregates only those rows that were needed....the reset button returns the entire list of possibilities with no entries)....my latest problem is I don't know how to add the buttons to the worksheet in Excel (Office 2007). I saw the Macro tab and re-created the code as I found it in his example....but how do I add the Command buttons...or whatever they are?

P.S. the friend isn't available until next week so I can't an answer from him


signed,
learning but still frustrated
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |