Excel Macro - Set Range to Text in Cell

roxy26girl

New Member
Joined
Apr 19, 2011
Messages
1
Hi,
I'm relatively new to VBA, so excuse me if this is a dumb question. I have a workbook with a tab that users enter different variables into. One cell is meant to input a range that later on will be used to perform selections on other tabs. I can't seem to set my range to the text in the input cell. An abbreviated form of the macro I'm trying to use is this:

Sub Macro1()
Dim RetrieveRange As range

Set RetrieveRange = range(Worksheets("Admin").range("B1").Text)

MsgBox RetrieveRange.Address

End Sub

I keep getting this error: "Run-time error '1004': Method 'Range' of object '_Global' failed"

Can anyone help?

Thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How about...

Code:
Sub Macro1()
    Dim RetrieveRange As Range
    Set RetrieveRange = Worksheets("Admin").Range("B1")
    MsgBox RetrieveRange.Address
End Sub
 
Upvote 0
Something like this:

Code:
Sub Macro1()
Dim RetrieveRange As Variant

Set RetrieveRange = Worksheets("Admin").Range("B1")

'Cell Address
MsgBox RetrieveRange.Address
'Cell Text
MsgBox RetrieveRange.Text

End Sub

Although from your description you want to take the text string from the cell and then select the range it refers to? If so this doesn't really get you where you want to be.
 
Upvote 0
You will need something more like this:

Code:
Sub Macro2()

Dim RetrieveRange As Range

Set RetrieveRange = Worksheets("Admin").Range(Worksheets("Admin").Range("B1").Value)

RetrieveRange.Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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