printing range using range variable

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,644
Office Version
  1. 365
Platform
  1. Windows
I can't see why the follwoing doesn't work
Code:
        Set rngStartCell = Range("A14")
        Set rngEndCell = Range("BV57")
        Set rngPrintRange = Range(rngStartCell, rngEndCell)
        With ActiveSheet.PageSetup
            .PrintArea = rngPrintRange
        End With
I had previously tried a different approach
Code:
        Set rngPrintRange = Range("A14:BV57")
        With ActiveSheet.PageSetup
            .PrintArea = rngPrintRange
        End With
I am struggling to understand why this doesn't work.....:confused:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I am curious as to why the range variable didn't work as I have similar code to print a different sheet
Code:
        Set rngStartCell = Range("A1")
        Do Until rngStartCell.Offset(intRowCountPrint, 0) = ""
            intRowCountPrint = intRowCountPrint + 1
        Loop
        Set rngPrintRange = Range(rngStartCell, rngStartCell.Offset(intRowCountPrint, 12))
        With ActiveSheet.PageSetup
            .PrintArea = rngPrintRange
        End With
This code works without any issues and all I did was adapt the code that doesn't using the same priciples as above.....:confused:

I do have more code within the 'With' line but didn't show on the thread as it wasn't relevant to the issue in hand and I would like to retain using the 'With' and 'End With' if possible
 
Upvote 0
I am curious as to why the range variable didn't work as I have similar code to print a different sheet
Code:
        Set rngStartCell = Range("A1")
        Do Until rngStartCell.Offset(intRowCountPrint, 0) = ""
            intRowCountPrint = intRowCountPrint + 1
        Loop
        Set rngPrintRange = Range(rngStartCell, rngStartCell.Offset(intRowCountPrint, 12))
        With ActiveSheet.PageSetup
            .PrintArea = rngPrintRange
        End With
This code works without any issues and all I did was adapt the code that doesn't using the same priciples as above.....:confused:

I do have more code within the 'With' line but didn't show on the thread as it wasn't relevant to the issue in hand and I would like to retain using the 'With' and 'End With' if possible

The PrintArea property can't use a range reference, it needs an A1 style reference. If you use rngPrintRange.Address, that will give it the required A1 style it needs.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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