VB Code: Print area across hidden columns (where number of columns that are hidden changes weekly), but not to the end of the data

AliM01

New Member
Joined
May 28, 2015
Messages
3
I want to select/print columns on the right of and including “A,” across the hidden columns (which changes), to include 16 columns for printing in a relative manner.

Background:
Visual basic macro in Excel 2010 using Windows 8.
I have a workbook that has hidden columns (relating to previous weeks), and each week the number of columns that are hidden, change (by another user).
The first two columns contain text labels (A&B) and stay constant. So this week I see Columns A, B,| GH, GI, GJ etc, next week it will be A, B, | GI, GJ, GK etc.
I want to select columns on the right of and including “A” across the hidden rows, to include 16 columns for printing.
I tried recording in relative mode but that didn’t work. Ie. Shift + end + down, then shift+right arrow 16 x.
Data is continuous and goes beyond the area I want to print so using selection.End(xlright) selects too much data.
I am not the workbook owner so have created a macro in my personal workbook to use.
I am not a programmer and realise this can be tidied up (as select doesn’t need to be used) but I and am out of my depth here and would appreciate your help

Have searched the web and played with ActiveCell.Offset but I can’t get it to work due to the hidden columns changing weekly.
Here are some that I have tried.

Sub 1 – macro recorded in relative mode
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:GU144").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$GU$144"
ActiveCell.Select
End Sub

Sub 2 – using offset - I am using this macro at the moment.
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.Offset(0, 204)).Select
ActiveSheet.PageSetup.PrintArea = Selection.Address
End Sub

Sub 3 using ActiveCell
Range( _
ActiveCell.End(xlDown), _
ActiveCell.Offset(0, 204)).Select
ActiveCell.End(xlUp).Offset(1, 0),
ActiveSheet.PageSetup.PrintArea = Selection.Address
End Sub

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this...
Code:
[color=darkblue]Sub[/color] Macro1()
    [color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    i = 16
    [color=darkblue]Do[/color] [color=darkblue]Until[/color] Range("A1").Resize(, i).SpecialCells(xlCellTypeVisible).Count = 16
        i = i + 1
    [color=darkblue]Loop[/color]
    ActiveSheet.PageSetup.PrintArea = Range("A1").Resize(ActiveSheet.UsedRange.Rows.Count, i).Address
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Last edited:
Upvote 0
Dear AlphaFrog.
Thank you very much for your response – Definitely on the right track as it prints the correct number of columns that I want.
However it prints several pages of blank rows, beneath what I require to be printed..
How do I incorporate the requirement to print only the rows with data. Previously I had;
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
… and that worked.
 
Upvote 0
Code:
[color=darkblue]Sub[/color] Macro1()
    [color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    i = 16
    [color=darkblue]Do[/color] [color=darkblue]Until[/color] Range("A1").Resize(, i).SpecialCells(xlCellTypeVisible).Count = 16
        i = i + 1
    [color=darkblue]Loop[/color]
    ActiveSheet.PageSetup.PrintArea = Range("A1", Cells(Range("A" & Rows.Count).End(xlUp).Row, i)).Address
End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,203,696
Messages
6,056,764
Members
444,891
Latest member
MelissaBr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top