VBA different display screen size issue

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am currently using below code to try automatically display same screen for different screen sizes on multiple worksheets. Cell range adjusted depending on Cell range width.

VBA Code:
Private Sub Worksheet_Activate()
 Sheet1.Range("B1:O30").Select
    ActiveWindow.Zoom = True
    Range("A1").Select
    
End Sub

However, I found that while this would work for some sheets it wouldn't work for others. Everything would line up perfectly on 13 inch screen but not 24inch and vice versa. I tried measuring and re-adjusting cells width to exactly same size within selected area but this has not worked yet either. What am I doing wrong? Any help would be greatly appreciated.

Code for measuring selected area width

VBA Code:
Sub MeasureSelection_Points()

Dim cell As Range
Dim Width As Double
Dim Height As Double

'Measure Selection Height
  For Each cell In Selection.Cells.Columns(1)
    Height = Height + cell.Height
  Next cell

'Measure Selection Width
  For Each cell In Selection.Cells.Rows(1)
    Width = Width + cell.Width
  Next cell

'Report Results
  MsgBox "Height:  " & Round(Height / 72, 2) & "pts" & vbCr & "Width:   " _
   & Round(Width / 72, 2) & "pts", , "Dimensions"

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top