VBA | With opening/activating sheet > edit viewing screen/zoom

TimvMechelen

Board Regular
Joined
Nov 7, 2016
Messages
121
Hi all,

When I activate a sheet I want excel to do the following process:

Is cell "Z1" in the range of my screen?

Yes:
Do nothing

No:
Code:
Range("A1:Z1").Select
ActiveWindow.Zoom = True

I want this because my file has to open on different screens/screen resolutions and everything has to be visible.


I hope somebody can help me.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Put this in the worksheet object in VBA

Code:
Private Sub Worksheet_Activate()
If ActiveWindow.Zoom > 100 Then ActiveWindow.Zoom = 100
End Sub
 
Upvote 0
This code doesn't work for me. What I need, is:
When cell Z1 isn't in my screen/view THEN Range("A1:Z1").Select
ActiveWindow.Zoom = True
 
Upvote 0
You might consider the following...

Code:
Private Sub Worksheet_Activate()
If Intersect(ActiveWindow.VisibleRange, Range("Z1")) Is Nothing Then
    Range("A1:Z1").Select
    ActiveWindow.Zoom = True
End If
End Sub

Cheers,

tonyyy
 
Upvote 0
You might consider the following...

Code:
Private Sub Worksheet_Activate()
If Intersect(ActiveWindow.VisibleRange, Range("Z1")) Is Nothing Then
    Range("A1:Z1").Select
    ActiveWindow.Zoom = True
End If
End Sub

This code always does
Code:
Range("A1:Z1").Select
ActiveWindow.Zoom = True

That code only has to be activated when I activate the sheet and Cell Z1 is not visable in my screen

Thanks for your time
 
Upvote 0
I fixed the problem with this code:

Code:
Private Sub Worksheet_Activate()

If CellIsInVisibleRange(ActiveSheet.Range("Z2")) Then

'Nothing
Else
    Range("A2:Z2").Select
    ActiveWindow.Zoom = True
    Range("D3").Select
End If

End Sub

Function CellIsInVisibleRange(cell As Range)

CellIsInVisibleRange = Not Intersect(ActiveWindow.VisibleRange, cell) Is Nothing

End Function
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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