View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default How to index a variable in VBA

Jared,
This shows you how to use a dynamic array with Redim. If you will always
require 50 elements use can just use
Dim Locations(1 to 50) As Variant
'or if you have string/numeric values declare as such

Not sure if you really want the first 50 cells of the worksheet, but I added
the debug line so you can see where you are getting values from.

Dim Locations() As Variant
Const MIN_ELEMENT As Long = 1
Const MAX_ELEMENT As Long = 50
Dim i As Long

ReDim Locations(MIN_ELEMENT To MAX_ELEMENT)

For i = MIN_ELEMENT To MAX_ELEMENT
Debug.Print Worksheets(1).Cells(i).Address
Locations(i) = Worksheets(1).Cells(i).Value
Next i

NickHK

"Jared" wrote in message
...
I am trying to create a loop that will enter data according to a loop but

no
success:
I have location1,Location2 Location3 Variables Up to 50 How do i correct
this so it works?

For i= 1 to 50
location(i)=Worksheets(1).cells(i).value
Next i
End Sub