Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problem with Auto Fit Sub on open

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Problem with Auto Fit Sub on open

You might want to use the EntireColumn property...

Worksheets("Inquiry").Range("B2:B100").EntireColum n.AutoFit

HTH

--
Regards,
Zack Barresse, aka firefytr
MsgBox "fire" & "fytr" & Chr(64) & "vba" & "express" & Chr(46) & "com"



"Qaspec" wrote in message
...
I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Problem with Auto Fit Sub on open

Hi
works OK on my machine (Excel 2002). Is there more to the code? What
does the data in the range look like?
regards
Paul

On Mar 22, 3:23 pm, Qaspec wrote:
I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")

Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Problem with Auto Fit Sub on open

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problem with Auto Fit Sub on open

I found my problem, there are a couple of cells in the range that are merged.
Is there any way to take the merged cells into account. Maybe I can set them
to a predetermined size and autosize anything that isnt a merged cell?
Because of the sort I can never be sure which rows will contain the merged
cells. Thanks

"Tom Ogilvy" wrote:

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Problem with Auto Fit Sub on open

Instead, how about looking for a way to un-merge the cells. They cause more
problems than they benefit.

--
Regards,
Zack Barresse, aka firefytr
MsgBox "fire" & "fytr" & Chr(64) & "vba" & "express" & Chr(46) & "com"



"Qaspec" wrote in message
...
I found my problem, there are a couple of cells in the range that are
merged.
Is there any way to take the merged cells into account. Maybe I can set
them
to a predetermined size and autosize anything that isnt a merged cell?
Because of the sort I can never be sure which rows will contain the merged
cells. Thanks

"Tom Ogilvy" wrote:

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problem with Auto Fit Sub on open

I wish it were that easy. Due to the way we are using the cells to copy from
excel into another application simple fixes like changing the column width or
font size aren't available for me. The only way to get rid on the merged
cells is to figure out a way to increase the 409.5 height limit on a cell.

"Zack Barresse" wrote:

Instead, how about looking for a way to un-merge the cells. They cause more
problems than they benefit.

--
Regards,
Zack Barresse, aka firefytr
MsgBox "fire" & "fytr" & Chr(64) & "vba" & "express" & Chr(46) & "com"



"Qaspec" wrote in message
...
I found my problem, there are a couple of cells in the range that are
merged.
Is there any way to take the merged cells into account. Maybe I can set
them
to a predetermined size and autosize anything that isnt a merged cell?
Because of the sort I can never be sure which rows will contain the merged
cells. Thanks

"Tom Ogilvy" wrote:

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Problem with Auto Fit Sub on open

Autofit doesn't work with merged cells.


this code by Jim Rech

Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Sub

may get you started. It is fairly specialized in what it handles, but you
might be able to incorporate it into you situation or use the method shown.
Obviously no guarantees since I have no idea what your data looks like.
--
Regards,
Tom Ogilvy



"Qaspec" wrote:

I found my problem, there are a couple of cells in the range that are merged.
Is there any way to take the merged cells into account. Maybe I can set them
to a predetermined size and autosize anything that isnt a merged cell?
Because of the sort I can never be sure which rows will contain the merged
cells. Thanks

"Tom Ogilvy" wrote:

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


End Sub


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problem with Auto Fit Sub on open

Thanks, I also realized I'mnot even making it to the Sizing portion of my
macro. The code stops at the Sort portion due to the cells "merged cells" not
being "identically sized". I tried to size the rows and columns so before the
sort runs every cell in the range is the same height and width but it still
returns the "identically sized" error.

Private Sub Workbook_Open()

With ThisWorkbook

.Worksheets("Concern").Rows("2:100").RowHeight = 20
.Worksheets("Concern").Columns("A:B").ColumnWidth = 20

.Worksheets("Concern").Range("A2:B100").Sort _
Key1:=.Worksheets("Concern").Range("A2"), _
Key2:=.Worksheets("Concern").Range("B100")

End With

End Sub

"Tom Ogilvy" wrote:

Autofit doesn't work with merged cells.


this code by Jim Rech

Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Sub

may get you started. It is fairly specialized in what it handles, but you
might be able to incorporate it into you situation or use the method shown.
Obviously no guarantees since I have no idea what your data looks like.
--
Regards,
Tom Ogilvy



"Qaspec" wrote:

I found my problem, there are a couple of cells in the range that are merged.
Is there any way to take the merged cells into account. Maybe I can set them
to a predetermined size and autosize anything that isnt a merged cell?
Because of the sort I can never be sure which rows will contain the merged
cells. Thanks

"Tom Ogilvy" wrote:

try

Private Sub Workbook_Open()

With ThisWorkbook
.Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=.Worksheets("Inquiry").Range("A2"), _
Key2:=.Worksheets("Inquiry").Range("B100")


.Worksheets("Inquiry").Range("B2:B100").EntireRow. AutoFit
End With

End Sub

--
Regards,
Tom Ogilvy


"Qaspec" wrote:

I have the follwoign code to Sort a column on a worksheet and resize to
autofit but I keep getting run time error 1004. Any Advice?

Private Sub Workbook_Open()

Worksheets("Inquiry").Range("A2:B100").Sort _
Key1:=Worksheets("Inquiry").Range("A2"), _
Key2:=Worksheets("Inquiry").Range("B100")


Worksheets("Inquiry").Range("B2:B100").Rows.AutoFi t


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
Auto Open problem Jim Excel Discussion (Misc queries) 1 December 7th 07 11:59 AM
open up an excel program with an auto open macro [email protected] Excel Programming 2 July 17th 05 04:48 PM
auto open, auto close mike allen[_2_] Excel Programming 1 December 31st 04 09:20 AM
still having problem with open currently open excel file John Coon Excel Programming 2 September 4th 04 04:34 PM
Problem With Auto Open Graham[_5_] Excel Programming 4 April 3rd 04 04:02 AM


All times are GMT +1. The time now is 08:30 PM.

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

About Us

"It's about Microsoft Excel"