Results 1 to 2 of 2

Thread: ByRef Error

  1. #1
    Join Date
    Dec 2003
    Posts
    268

    Unanswered: ByRef Error

    I am trying to dynamically create the naming scema for columns like with excel in 26 letter chunks. Here is what I got so far, but am getting compile errors. "Compile Error: Type Mismatch: array or user-defined type expected"

    Can any one help?

    Public Sub AddColumnNames(ByRef Columns() As String)
    'this function adds additional 26 values to string array for excel file
    Dim x As Integer
    Dim i As Integer
    Dim j As Integer

    x = UBound(Columns) Mod 26

    ReDim Columns(26 * (x + 1))

    Do While i < 26
    For j = 0 To 25
    Columns(26 * x + i) = Columns(x) & Columns(i)
    Next j
    Loop
    End Sub

    Sub TestColumnStuff()

    Dim xlColumns(26) As String
    Dim x As Integer
    For x = 65 To 90
    xlColumns(x - 65) = Chr(x)
    Next x
    x = 0
    For x = 0 To 52
    If x Mod 26 = 0 Then
    AddColumnNames (xlColumns)
    End If
    Debug.Print xlColumns(x)
    Next x
    End Sub


    Thanks.
    Last edited by mjweyland; 08-06-04 at 12:50.

  2. #2
    Join Date
    Aug 2004
    Posts
    40
    Try changing

    Dim xlColumns(26) As String

    to

    Dim xlColumns(26) As Variant

    That is what fixed my last problem exporting to excel.

    Howard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •