Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2022, 10:37 AM
bacothran01 bacothran01 is offline Automate fit worksheet width to fit screen Windows 10 Automate fit worksheet width to fit screen Office 2013
Novice
Automate fit worksheet width to fit screen
 
Join Date: Jul 2022
Location: Ohio
Posts: 2
bacothran01 is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 07-13-2022, 11:47 AM
Logit Logit is offline Automate fit worksheet width to fit screen Windows 10 Automate fit worksheet width to fit screen Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

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
Reply With Quote
  #3  
Old 07-13-2022, 12:17 PM
bacothran01 bacothran01 is offline Automate fit worksheet width to fit screen Windows 10 Automate fit worksheet width to fit screen Office 2013
Novice
Automate fit worksheet width to fit screen
 
Join Date: Jul 2022
Location: Ohio
Posts: 2
bacothran01 is on a distinguished road
Default

Thank you. I look forward to trying it.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate fit worksheet width to fit screen 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
Automate fit worksheet width to fit screen Word 2012: Change column width changes table width OpfinnarJocke Word Tables 1 09-22-2012 04:03 AM
Automate fit worksheet width to fit screen How to summarise different worksheet to a summary worksheet samkiewhock Excel 1 09-06-2012 03:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft