Link to home
Start Free TrialLog in
Avatar of greg_c
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
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

With Sheet1
        For myCount = 1 To UBound(myArray)
            .Cells(1, myCount).Value = myArray(myCount - 1)
        Next myCount
    End With

Kevin
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want the default base to be 1 use this:

Option Base 1

at the top of your code module.

Kevin
Avatar of greg_c
greg_c

ASKER

Thank you.