Range question...

Agenth22

New Member
Joined
Dec 12, 2005
Messages
10
I have the following code:

Code:
Dim PasteRng As Range
On Error Resume Next
Set PasteRng = Application.InputBox("What cell do you want your data in?", Type:=8)
If PasteRng Is Nothing Then Exit Sub

It returns a range object, "PasteRng".

If i declare a variable: Dim Variable1 as Range, how do i set Variable1 equal to PasteRng offset by lets say 1 cell?

I tried a bunch of different things and nothing seems to work. I've tried:
Code:
Dim Variable1 As Range
Variable1 = Cells(PasteRng.Row + 1, PasteRng.Column)
'& 
Variable1 = PasteRng.offset(1,0)
msgbox(Variable1.address)

and some others that i have since deleted. Does anyone have any suggestions?

Thanks!!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi, Agenth22,

try this
Code:
Sub test()
Dim PasteRng As Range
On Error Resume Next
Set PasteRng = Application.InputBox("What cell do you want your data in?", Type:=8)
If PasteRng Is Nothing Then Exit Sub

Dim Variable1 As Range
Set Variable1 = PasteRng.Offset(1, 0)
PasteRng.Interior.ColorIndex = 6
Variable1.Select
End Sub

kind regards,
Erik
 
Upvote 0
why do you need to do this?

why not just type a different cell number in the input box?

Alternatively, this will work

Set Variable1 = PasteRng.Offset(1,0)

Just like you are setting the PasteRng object, you must also "Set" the variable1 Range object.
 
Upvote 0
Eric.van.Geit and Gibbs, thanks a bunch for your help. I would have spent another couple hours trying to figure that out if one of you didn't chime in.

why do you need to do this?

why not just type a different cell number in the input box?

That would seem like the obvious thing to do. However, the user will select a cell. that cell will be where 2 columns of data will be placed with a header. I need a way of telling the program to offset data from the header by a cell or 2.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

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