Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Worksheet_SelectionChange

0

I'm using this in my workbook on sheet 1.

Private Sub Worksheet_SelectionChange

'THIS ZOOMS IN DURING "CLASS" SELECTION, AND ZOOMS OUT AFTER SELECTION

Dim KeyCells As Range

ActiveWindow.Zoom = 65

Set KeyCells = Range("a_class")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _

Is Nothing Then

ActiveWindow.Zoom = 90

Else

ActiveWindow.Zoom = 65

End If

End Sub

This cell is linked to a dropdown list.  When I open this cell (a_class), the sheet zooms in to 90% to enlarge the dropdown listings.    (Excel has no way to enlarge the font of dropdown list) When I move to another cell, the sheet zooms back to 65%.  That is all well and good. 

The problem is when it zooms in, the sheet moves over about one column.  But when it zooms back to 65%, it doesn't move back to the left most margin.

What can I do to move this worksheet back to left most margin, using  this macro?

Answer
Discuss

Discussion

Sorry if you were notified earlier of an answer then found none - I deleted one I'd posted from memory (but then realised I'd made a mistake). I've now added an answer.
John_Ru (rep: 6152) Dec 23, '22 at 2:43 pm
OK this works great.  I put one in fromt of the zoom to 90, to =4.  Keeps the zoom centered and put one (+1) befor the end if, to move it back.  Thanks again.
orkrj (rep: 14) Dec 24, '22 at 3:57 pm
Glad you could modify that approach to work for you. Thanks for selecting my answer 
John_Ru (rep: 6152) Dec 24, '22 at 6:31 pm
Add to Discussion

Answers

0
Selected Answer

Hi Orkrj

You can force "this worksheet back to left most margin" by adding the line:

ActiveWindow.ScrollColumn = 1

after your End If.

Hope this helps

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login