Range Macro

imi123

New Member
Joined
Jun 8, 2011
Messages
8
I have a spreadsheet, where I am trying to set a range via macro to print, but every month a new column is added. The rows remain the same. Can you suggest a macro I can create to capture any new columns.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Perhaps like this

Code:
Sub prt()
With ActiveSheet
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
End Sub
 
Upvote 0
Hi,

Your macro works for one sheet but I have mulitple sheets, If I copy paste the coding and change the name of the sheets accordingly, the macro stops working:

Here is what I have:

Sub prt()
Sheets("3. Summary of Results 1Q2011").Select
.PageSetup.PrintArea = .UsedRange.Address
.PrintOut
Sheets("5. Accrued Claims").Select
.PageSetup.PrintArea = .UsedRange.Address
.PrintOut
Sheets("6. Mix History").Select
.PageSetup.PrintArea = .UsedRange.Address
.PrintOut
Sheets("14. Data Updated").Select
.PageSetup.PrintArea = .UsedRange.Address
.PrintOut
Sheets("1Q2011").Select
.PageSetup.PrintArea = .UsedRange.Address
.PrintOut
End With
End Sub
 
Upvote 0
Try

Code:
Sub prt()
With Sheets("3. Summary of Results 1Q2011")
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
With Sheets("5. Accrued Claims")
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
With Sheets("6. Mix History")
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
With Sheets("14. Data Updated")
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
With Sheets("1Q2011")
    .PageSetup.PrintArea = .UsedRange.Address
    .PrintOut
End With
End Sub
 
Upvote 0
Or, better

Code:
Sub prt()
Dim ws As Worksheet
For Each ws In Worksheets(Array("3. Summary of Results 1Q2011", "5. Accrued Claims", "6. Mix History", "14. Data Updated", "1Q2011"))
    With ws
        .PageSetup.PrintArea = .UsedRange.Address
        .PrintOut
    End With
Next ws
End Sub
 
Upvote 0
Hey- What if for one of the tabs you dont want to print to a certain amount of rows...I have some comments and cells with data that I dont want to see on the print out...I want to restrict the macro to a certain range of rows but at the same time recognize any new columns being added...
 
Upvote 0
Try recording a macro whilst setting the print area and posting the recorded code here.
 
Upvote 0
' Printtest Macro
'
'
Sheets("4. 80% Reserves 1Q2011").Select
Range("A1:CC37").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$CC$37"
Sheets("5. Accrued Claims").Select
Range("B1:BD21").Select
ActiveSheet.PageSetup.PrintArea = "$B$1:$BD$21"
Sheets("6. Mix History").Select
Sheets("7. 1Q Paid & Accrued").Select
Range("A1:BD219").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$BD$219"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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