Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Subject: Type 13 Error when defining a Columns variable

Hi Mike

Columns (and rows) has to be defined as Range variables. You can call
another Sub to autosize all columns, but I don't see any reason to do it
like that. In one macro it can be done like this:

Private Sub z20_Set_This_Range_from_Array(rng1Cell As Range, arr() As
Variant, Optional autoFitCols As Boolean)
Dim r As Long, c As Long
Dim pasteRange As Range
Dim Col As Range
Dim cMax As Double

r = UBound(arr, 1) - LBound(arr, 1)
c = UBound(arr, 2) - LBound(arr, 2)
cMax = 18

Set pasteRange = Range(rng1Cell, rng1Cell.Offset(r, c))
pasteRange = arr

pasteRange.Columns.AutoFit
For Each Col In pasteRange.Columns
If Col.Width cMax Then Col.Width = cMax
Next
End Sub

Hopes this helps

---
Per

"MikeZz" skrev i meddelelsen
...
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable as subject of SET Lucas Excel Programming 3 July 31st 08 11:54 AM
Defining Variable Type for Items and Keys in Dictionary ExcelMonkey Excel Programming 5 May 4th 07 09:22 PM
Defining a type of the cell backspace Excel Programming 1 September 7th 06 11:09 AM
Defining the subject of an Email by value in range RPIJG[_31_] Excel Programming 5 June 8th 04 09:00 PM
Defining input box data type? Big Chris[_30_] Excel Programming 4 January 30th 04 04:13 PM


All times are GMT +1. The time now is 06:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"