assign variable to a range defined with cells

kato01

Board Regular
Joined
Sep 9, 2005
Messages
81
I am trying to assign a variable to a range define using the cells command.

what I have is this:

Dim a1 As Range
Set a1 = Range(Sheets("sheet1").Cells(i, 2), Cells(i, 5))

It does not seem to work.

Thank you
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You need to qualify the 2nd Cells, in the same way as the first.
Otherwise it's trying to sat a range across two sheets.
 
Upvote 0
not sure I understand.
what I am trying to do is assign all cells in a range a hyperlink defined by the content of each cell in the range, i.e the hyperlink of A1 is the value of A1.

Public Sub ****()
Dim a1 As Range
Dim b1 As Range
Set a1 = Range(Sheets("sheet1").Cells(i, 2), Sheets("sheet1").Cells(i, 5))
For i = 1 To 1000
If InputRange.a1.Hyperlinks.Count > 0 Then
OutputRange.a1.Hyperlinks.Add Anchor:=a1, _
Address:=InputRange.a1.Hyperlinks(1).Address
End If
Next i
End Sub
 
Upvote 0
Please explain exactly what you are trying to do.
 
Upvote 0
i have a bunch (in fact 800) of cells populated with text that are links.
for example say
a1.value is "www.msn.com"
a2.value is "www.google.com"
.
.
a10.value is "www.facebook.com"


I would like to assign to each cell a hyperlink to get somehting like:

sheet1.cells(1,1).Address:="http://www.msn.com" , TextToDisplay:="www.msn.com"
sheet1.cells(1,2).Address:="http://www.google.com" , TextToDisplay:="www.google.com"
.
.
.
sheet1.cells(1,2).Address:="http://www.facebook.com" , TextToDisplay:="www.facebook.com"
 
Upvote 0
Ok, as that is completely different from your original question, please start a new thread.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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