#1
|
|||
|
|||
Automate fit worksheet width to fit screen
I have a workbook with multiple tabs. Each tab has different numbers of active columns. I would like for each tab to fit to the screen's width upon opening the workbook so that there are no empty columns showing.
Any help would be greatly appreciated. |
#2
|
|||
|
|||
The following works with the ZOOM setting. Run the macro once it attempts to magnify ... run it again to reset :
Code:
Sub ZoomUR() Dim Tmp As String If ActiveWindow.Zoom <> 100 Then ActiveWindow.Zoom = 100 Else Tmp = ActiveCell.Address ActiveSheet.UsedRange.Select ActiveWindow.Zoom = True Range(Tmp).Select End If End Sub This next macro merely hides the empty columns set within a range : Code:
'If the entire Column is empty : Sub HideCol() Dim N As Long, wf As WorksheetFunction, M As Long Dim i As Long, j As Long N = Columns.Count M = Rows.Count Set wf = Application.WorksheetFunction Application.ScreenUpdating = False For i = 26 To 1 Step -1 '<<<---------------------------- Change 26 (Col Z) to reflect max columns possible If wf.CountBlank(Columns(i)) <> M Then Exit For Next i For j = i To 1 Step -1 If wf.CountBlank(Columns(j)) = M Then Cells(1, j).EntireColumn.Hidden = True End If Next j Application.ScreenUpdating = True End Sub |
#3
|
|||
|
|||
Thank you. I look forward to trying it.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Link UserForm checkbox to corresponding shape on one worksheet and copy to 'template' worksheet | kiwimtnbkr | Excel Programming | 23 | 10-08-2020 02:32 AM |
Pinning a worksheet to screen | howie707 | Excel | 6 | 12-16-2013 03:46 PM |
New Monitor: Print Preview Screen On Left Side of Screen, Not Centered | tatihulot | Word | 1 | 09-11-2013 02:47 AM |
Word 2012: Change column width changes table width | OpfinnarJocke | Word Tables | 1 | 09-22-2012 04:03 AM |
How to summarise different worksheet to a summary worksheet | samkiewhock | Excel | 1 | 09-06-2012 03:34 AM |