Name range

Svgmassive

Board Regular
Joined
Nov 2, 2010
Messages
113
I am trying to loop through names ranges to set up their values etc.I am using an array to store the name ranges i tried different methods i can't get it to work.Thanks

dim H_NAMES() as string
dim i as long
ReDim H_NAMES(1 To 4)

H_NAMES(1) = "test"
H_NAMES(2) = "east"
H_NAMES(3) = "west"
H_NAMES(4) = "north"
For i = LBound(H_NAMES) To UBound(H_NAMES)
Debug.Print Range(H_NAMES(i)).Address
next
 

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.
What are you trying to do with this statement?

Debug.Print Range(H_NAMES(i)).Address
 
Upvote 0
I was just testing it to see if it works.Once it does then i am going to populate the ranges with their respective header names.Month,year,day etc.
 
Upvote 0
Code:
Sub Foo()
Dim H_NAMES() As String
Dim i As Long
ReDim H_NAMES(1 To 4)

H_NAMES(1) = "test"
H_NAMES(2) = "east"
H_NAMES(3) = "west"
H_NAMES(4) = "north"
For i = LBound(H_NAMES) To UBound(H_NAMES)
'*******  All code to this point works OK ****
'*****  I dumped the output to the Cell Range(A1:A4)  ***


ActiveSheet.Cells(i, 1).Value = H_NAMES(i)
Next
End Sub
 
Upvote 0
hi jim
what i am trying to do is to populate name ranges "east" etc. with header just in case the user insert columns and rows etc.i can still get the name range locations

that's why i need the range stuff to work.Thanks

Debug.Print Range(H_NAMES(i)).Address
 
Upvote 0
hi jim I found out what my problem was the first name in the array was spelt wrong that made the loop fail i tried on error resume next that is when i found out what the problem was. this worked.Thanks

Range(H_NAMES(i)) = H_NAMES(i)
 
Upvote 0
Maybe (Change to suit)

Code:
Sub Foo()
Dim H_NAMES() As String
Dim i As Long
ReDim H_NAMES(1 To 4)

H_NAMES(1) = "test"
H_NAMES(2) = "east"
H_NAMES(3) = "west"
H_NAMES(4) = "north"
For i = LBound(H_NAMES) To UBound(H_NAMES)
'******  All code to this point works OK ****

ActiveWorkbook.Names.Add H_NAMES(i), RefersTo:=Cells(1, i)
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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