greg_c
asked on
VBA Array
Hi
For some reason the following array won't populate 'Name' into A1. Can someone explain why?
Sub ColumnHeaders()
Dim myArray As Variant ' Variants can hold any type of data, including arrays
Dim myCount As Integer
'myArray = Range("A1:D1").Value
'Fill the variant with array data
myArray = Array("Name", "Address", "Phone", "Email")
'Empty the array
With Sheet1
For myCount = 1 To UBound(myArray)
.Cells(1, myCount).Value = myArray(myCount)
Next myCount
End With
End Sub
Greg
For some reason the following array won't populate 'Name' into A1. Can someone explain why?
Sub ColumnHeaders()
Dim myArray As Variant ' Variants can hold any type of data, including arrays
Dim myCount As Integer
'myArray = Range("A1:D1").Value
'Fill the variant with array data
myArray = Array("Name", "Address", "Phone", "Email")
'Empty the array
With Sheet1
For myCount = 1 To UBound(myArray)
.Cells(1, myCount).Value = myArray(myCount)
Next myCount
End With
End Sub
Greg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want the default base to be 1 use this:
Option Base 1
at the top of your code module.
Kevin
Option Base 1
at the top of your code module.
Kevin
ASKER
Thank you.
For myCount = 1 To UBound(myArray)
.Cells(1, myCount).Value = myArray(myCount - 1)
Next myCount
End With
Kevin