Excel: set a range by its name [SELF-RESOLVED]
I have this VBA code in a Excel spreadsheet:
VB Code:
Dim vTarget As range
Private Sub Workbook_Open()
Set vTarget = Range("Sheet1!$B$3")
End Sub
Now, cell $B$3 has been assigned the name "Volume". I want to set the vTarget variable using the name "Volume" rather than the cell address. I've tried different syntax but always get some kind of error.
Re: Excel: set a range by its name
VB Code:
Dim vTarget As range
Private Sub Workbook_Open()
Set vTarget = Range(ThisWorkbook.Names("Volume"))
End Sub
It wasn't that difficult after all.
Re: Excel: set a range by its name [SELF-RESOLVED]
VB Code:
Private Sub Workbook_Open()
Dim vTarget As range
Set vTarget = Range("Volume")
End Sub
That will also work.
zaza
Re: Excel: set a range by its name [SELF-RESOLVED]
Quote:
Originally Posted by zaza
VB Code:
Private Sub Workbook_Open()
Dim vTarget As range
Set vTarget = Range("Volume")
End Sub
That will also work.
zaza
Right, thanks for pointing out.