Reputation: 115
I want to include just one column from a spreadsheet in print area but users can add a lot of rows so the column can grow dynamically. I want that column to be entirely included in print area. So, if say 10 rows were added, it would print those new 10 rows too. How would I do that in Excel VBA? There seem to be several methods of going about it from what I saw on the web but I am using this for the first time so I would appreciate your input on this. Thank you.
Upvotes: 0
Views: 658
Reputation: 14764
You do not need VBA for this.
Here is what to do.
Switch to the sheet you wish to have the dynamic print range on, say Sheet1.
Open the Name Manager with Control-F3.
Click the New button at the top.
For the Name field enter: print_area
For the Scope field select Sheet1 (or whichever sheet you are on).
For the Refers To field paste this formula:
=$A$1:INDEX($A:$A,MAX(IFERROR(MATCH({"*";9E+99},$A:$A,{-1;1}),1)))
Click OK and then Close
That's it.
Now as column A is added to the print range will include all of column A and nothing else... for that sheet only.
Note: If you want this for a different column than column A, simply change the A's in the formula to the different column label.
Upvotes: 1