M
MikeZz
Hi,
I have a routine that pastes an array to a worksheet.
I want to have it call another routine that autosizes all the columns at
once, then if any column widths excede my max, it sets width to max.
Everthing comes to an "Error 13" Wrong Type crash at this line:
Set cols = pasteRange .Columns
I'm not sure if I'm defining the variable wrong or what.
Any help would be great,
Thanks,
MikeZz
Private Sub z20_Set_This_Range_from_Array(rng1Cell As Range, arr() As
Variant, Optional autoFitCols as Boolean)
Dim r, c
Dim cols As Columns
Dim pasteRange As Range
r = UBound(arr, 1) - LBound(arr, 1)
c = UBound(arr, 2) - LBound(arr, 2)
Set pasteRange = Range(rng1Cell, rng1Cell.Offset(r, c))
pasteRange = arr
If IsMissing(autoFitCols) Then
Else
Set cols = pasteRange .Columns
If autoFitCols = True Then _
Call z30_Set_Auto_Column_Size_With_Max(cols, 25)
Set cols = Nothing
End If
End Sub
Sub z30_Set_Auto_Column_Size_With_Max(cols As Columns, cMax)
Dim col As Column
cols.AutoFit
For Each col In cols
If col.Width > cMax Then col.Width = cMax
Next col
End Sub
I have a routine that pastes an array to a worksheet.
I want to have it call another routine that autosizes all the columns at
once, then if any column widths excede my max, it sets width to max.
Everthing comes to an "Error 13" Wrong Type crash at this line:
Set cols = pasteRange .Columns
I'm not sure if I'm defining the variable wrong or what.
Any help would be great,
Thanks,
MikeZz
Private Sub z20_Set_This_Range_from_Array(rng1Cell As Range, arr() As
Variant, Optional autoFitCols as Boolean)
Dim r, c
Dim cols As Columns
Dim pasteRange As Range
r = UBound(arr, 1) - LBound(arr, 1)
c = UBound(arr, 2) - LBound(arr, 2)
Set pasteRange = Range(rng1Cell, rng1Cell.Offset(r, c))
pasteRange = arr
If IsMissing(autoFitCols) Then
Else
Set cols = pasteRange .Columns
If autoFitCols = True Then _
Call z30_Set_Auto_Column_Size_With_Max(cols, 25)
Set cols = Nothing
End If
End Sub
Sub z30_Set_Auto_Column_Size_With_Max(cols As Columns, cMax)
Dim col As Column
cols.AutoFit
For Each col In cols
If col.Width > cMax Then col.Width = cMax
Next col
End Sub