NewDaddy
12-21-2006, 02:52 AM
Sub ColumnHeaders()
Dim myArray As Variant
Dim myCount As Integer
'Fill array
myArray = Array("Name", "Address", "Phone", "Email")
'Empty array
With Worksheets("Sheet1")
For myCount = 1 To UBound(myArray)
.Cells(1, myCount).Value = myArray(myCount)
Next myCount
End With
End Sub
Hi all
Attempting to understand arrays and have come up with the above example.
It works fine except it is missing the first value, "Name" so what I get is
Cell - A1, B1, C1
Value - Address, Phone, Email
For some reason it is ignoring "Name"?
I am not sure what is happening here?! I have tried a few things like changing the dimension? to myCount = 1 to 4, but this causing an error as it seems to only find 3 in the array.
Also can someone explain UBound(myArray) is doing? I have looked up UBound in the help files but cannot understand and I cant find a reference to UBound in my VBA book.
Can someone explain this in pain english?
Thank you very much.
Cheers
J
Dim myArray As Variant
Dim myCount As Integer
'Fill array
myArray = Array("Name", "Address", "Phone", "Email")
'Empty array
With Worksheets("Sheet1")
For myCount = 1 To UBound(myArray)
.Cells(1, myCount).Value = myArray(myCount)
Next myCount
End With
End Sub
Hi all
Attempting to understand arrays and have come up with the above example.
It works fine except it is missing the first value, "Name" so what I get is
Cell - A1, B1, C1
Value - Address, Phone, Email
For some reason it is ignoring "Name"?
I am not sure what is happening here?! I have tried a few things like changing the dimension? to myCount = 1 to 4, but this causing an error as it seems to only find 3 in the array.
Also can someone explain UBound(myArray) is doing? I have looked up UBound in the help files but cannot understand and I cant find a reference to UBound in my VBA book.
Can someone explain this in pain english?
Thank you very much.
Cheers
J