Trouble getting used to VBA

  • Thread starter Thread starter JF
  • Start date Start date
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
 
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
|
|
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top