Trouble getting used to VBA

J

JF

I am new to Visual basic and have made only a few
applications i was wondering if someone knew how to name a
range as a variable. The bottom part is where im having
the issue


Thanks

Jeff

Dim INS As Range

ActiveCell.Offset(0, 2).Select
Range(Selection, Selection.End(xlDown)).Select

' Trying to name the following range
INS = activeRange.Select

End Sub
 
J

Jim Rech

If you want to create an Excel name for a range (the same as Define Name):

Range(Selection, Selection.End(xlDown)).Name = "MyName"

If you want to create a range object variable for a range in VB:

Set INS = Range(Selection, Selection.End(xlDown))


--
Jim Rech
Excel MVP
|I am new to Visual basic and have made only a few
| applications i was wondering if someone knew how to name a
| range as a variable. The bottom part is where im having
| the issue
|
|
| Thanks
|
| Jeff
|
| Dim INS As Range
|
| ActiveCell.Offset(0, 2).Select
| Range(Selection, Selection.End(xlDown)).Select
|
| ' Trying to name the following range
| INS = activeRange.Select
|
| End Sub
|
|
 
A

Alan Beban

JF said:
I am new to Visual basic and have made only a few
applications i was wondering if someone knew how to name a
range as a variable. The bottom part is where im having
the issue


Thanks

Jeff

Dim INS As Range

ActiveCell.Offset(0, 2).Select
Range(Selection, Selection.End(xlDown)).Select

' Trying to name the following range
INS = activeRange.Select

End Sub

The following macro (Sub procedure) will assign the designated
range to the variable "INS":

Sub BBB()
Dim rngTemp As Range, INS As Range
Set rngTemp = ActiveCell(1, 3) '<---This is equivalent to
'Set rngTemp = ActiveCell.Offset(0, 2)
Set INS = Range(rngTemp, rngTemp.End(xlDown))
End Sub
 
Top