Thanks to everyone for your replies. Once I had UBound and LBound it was easy. For reference, here is the (much less elegant) solution I had originally come up with using error handlers. I worked, but ugh.
===========================
Private Function HdrChk(ByVal ShtName As String, ByVal ColHdrs As Variant) As Boolean
Dim i, d As Long
'set an offset value in case lbound < 1
d = 1 - LBound(ColHdrs)
'fill top row with header labels
For i = LBound(ColHdrs) To UBound(ColHdrs)
Worksheets(ShtName).Cells(1, i + d).Value = ColHdrs(i)
Next i
'return true. This boolean is currently a programming
'artifact, but it has been kept in case some error
'handling is desired.
HdrChk = True
Exit Function
End Function
Private Function XHdrChkX(ByVal ShtName As String, ByVal ColHdrs As Variant) As Boolean
Dim i As Long
On Error GoTo ErrHdlr
i = 1
Do Until True
Worksheets(ShtName).Cells(1, i).Value = ColHdrs(i)
i = i + 1
Loop
LoopExit:
XHdrChkX = True
Exit Function
ErrHdlr:
If Err = 9 Then
GoTo LoopExit
Else
XHdrChkX = False
Exit Function
End If
End Function
Per Jessen wrote:
Hi CraigIf you want to determine how many elements that has been loaded into
22-Nov-09
Hi Craig
If you want to determine how many elements that has been loaded into your
array, I think this is what you need:
Dim HRColHdrs(3) As Variant
Private Sub HdrChk(ByVal ShtName As String, ByRef ColHdrs As Variant)
Dim i As Long, n As Long
For i = LBound(ColHdrs) To UBound(ColHdrs)
If ColHdrs(i) < "" Then
n = n + 1
End If
Next
Debug.Print n & " elements are in this array"
End Sub
Regards,
Per
"Craig Remillard" skrev i meddelelsen
Previous Posts In This Thread:
EggHeadCafe - Software Developer Portal of Choice
SQL Injection - SQL Server Convert EXEC To Avoid Attacks
http://www.eggheadcafe.com/tutorials...sql-serve.aspx