VBA to automate sheet sizing not working

men5j2s

Board Regular
Joined
Apr 26, 2016
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Can anyone suggest why this code isn't working?

Is there another way to do it?

I want each sheet to open according to the cells (in columns) that I want visible, so it docent matter what screen size is in use.

Do I need to call the sheets by the names I have given them?


Sub Workbook_Open()


Application.ScreenUpdating = False


Sheet1.Range("a1:p1").Select
ActiveWindow.Zoom = True
Sheet5.Range("a1:n1").Select
ActiveWindow.Zoom = True
Sheet2.Range("a1:p1").Select
ActiveWindow.Zoom = True
Sheet3.Range("a1:p1").Select
ActiveWindow.Zoom = True
Sheet9.Range("a1:n1").Select
ActiveWindow.Zoom = True
Sheet6.Range("a1:s1").Select
ActiveWindow.Zoom = True
Sheet7.Range("a1:n1").Select



Application.ScreenUpdating = True
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
to call a particular range, this is the format you shoulduse

Code:
Worksheets("Sheet1").Range("A1:P1").Select

where "Sheet1" is whatever you have called the sheet (if you changed it from default)

Hopefully that will fix your issue

Caleeco
 
Last edited:
Upvote 0
Hi Caleeco,

So now I'm getting an error at the command for the 2nd sheet..

Could this be because I'm asking it to select cells on different sheets at the same time?

should I break up the code for each sheet?

Code:
Sub Workbook_Open()


Application.ScreenUpdating = False


Worksheets("CRM").Range("A1:I1").Select
ActiveWindow.Zoom = True
Worksheets("SalesLog").Range("A1:P1").Select
ActiveWindow.Zoom = True
Worksheets("Orders").Range("A1:P1").Select
ActiveWindow.Zoom = True
Worksheets("Reporting").Range("A1:P1").Select
ActiveWindow.Zoom = True
Worksheets("Client File").Range("A1:N1").Select
ActiveWindow.Zoom = True
Worksheets("Trends").Range("A1:S1").Select
ActiveWindow.Zoom = True
Worksheets("Compare").Range("A1:S1").Select




Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello,

try activating each sheet first, in this format:
Code:
Sub Test()

With Worksheets("CRM")
    .Activate
    .Range("A1:I1").Select
    ActiveWindow.Zoom = True
End With


With Worksheets("SalesLog")
    .Activate
    .Range("A1:P1").Select
    ActiveWindow.Zoom = True
End With

With Worksheets("Orders")
    .Activate
    .Range("A1:P1").Select
    ActiveWindow.Zoom = True
End With

End Sub
 
Last edited:
Upvote 0
No errors, but does nothing..

I even tried using just one section (to fix one sheet only) and put the code in the specific sheet (in the VBA editor), still nothing.

Surely if this works, the top row should be selected when i open right? because even that isn't happening
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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