Use Cell range instead of message box type 8

jasonfhaught

New Member
Joined
Mar 30, 2022
Messages
3
Office Version
  1. 365
I found a bit of code that works but would like to use without using the inputbox type 8

Set rPrintArea = Application.InputBox(Prompt:="Use Mouse to select area to Print.", Title:="Select Print Area", Type:=8)

I want to be able to do is Set rPrintArea = Range("A1:C20") but I have not yet been able to make it work.

Could you help me and explain what is going on with the statement
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I found a bit of code that works but would like to use without using the inputbox type 8

Set rPrintArea = Application.InputBox(Prompt:="Use Mouse to select area to Print.", Title:="Select Print Area", Type:=8)

I want to be able to do is Set rPrintArea = Range("A1:C20") but I have not yet been able to make it work.

Could you help me and explain what is going on with the statement
I should say that I get "object variable or with block variable not set"

Dim rPrintArea As Range
rPrintArea = Range("$C1:O1500")
 
Upvote 0
That is different from what you posted, which is what I would have suggested should work. When you declare an object variable, you must Set it to something (before you can use it), and you did use the Set keyword in your first post but not your second post. At the end of your code, it is advisable to clear object variables from memory:

Set rPrintArea = Nothing

A range is an object, btw.
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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