Problems Defining A Print Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to use VBA to creat a dynamic print range. What I have doesn't seem to be working. Will someone be kind enough to have a look at what I have and share with me where I have went wrong and a possible solution? The line in red is giving me a "Type mismatch error"

Rich (BB code):
Sub printme_d()
    dim rwtopLeft as Long, coltopLeft as Long
    dim rwbtmRight as ong, colbtmRight as Long
    dim diarng as range
    Stop
    rwtopLeft = Application.WorksheetFunction.VLookup("D", ws_lists.Range("X3:AD10"), 3, False)
    coltopLeft = Application.WorksheetFunction.VLookup("D", ws_lists.Range("X3:AD10"), 4, False)
    rwbtmRight = Application.WorksheetFunction.VLookup("D", ws_lists.Range("X3:AD10"), 5, False)
    colbtmRight = Application.WorksheetFunction.VLookup("D", ws_lists.Range("X3:AD10"), 6, False) + 26
    
    Set diarng = ws_front.Range(ws_front.Cells(rwtopLeft, coltopLeft), ws_front.Cells(rwbtmRight, colbtmRight))
    
    With ws_front.PageSetup
        ws_front.Unprotect
        .PrintArea = diarng 
        pgnums = .Pages.Count
        ws_front.Protect
    End With
    . . .
 

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).
I think I know the problem here, but I certainly don't know how to fix it.
The value for PrintArea has to be text. I'm try to use the range I want to set. How can I get the text equivalent of my range?
 
Upvote 0
Use the Range's Address property: .PrintArea = diarng.Address.

Address is very useful to verify that a Range is referencing the correct cells, particularly when adjusting a Range with the Offset, Resize and Item properties.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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