Center on Cell

bposaner

Board Regular
Joined
May 28, 2002
Messages
74
Hi

I've had a look around and can find anything really helpful.
I want to automatically centre and zoom in/out the worksheet on certain chosen cells.

For example:
A user enters/select cell, say "J76", and i want the page to centre on cell J76 and then zoom in to 150%, wait a few seconds and zoom back to 100% Then they may enter "B34" and then the page will recentre on B34, ETC.

Hopefully I've explained myself
Thanks for any help.
BP
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Okay, this works, but you can't do anything in the 5 second wait, so there's probably a better way.

Mostly stolen from this thread: http://www.mrexcel.com/forum/showthread.php?t=68193

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
Dim Rng As Range
Set Rng = ActiveCell
 
ActiveWindow.Zoom = 150
Application.Goto Target, True 'puts active cell in top left corner
Rng.Activate
With ActiveWindow
     On Error Resume Next
     .ScrollRow = Application.Max(1, .ScrollRow - .VisibleRange.Rows.Count \ 2 + Target.Rows.Count \ 2)
     .ScrollColumn = Application.Max(1, .ScrollColumn - .VisibleRange.Columns.Count \ 2 + Target.Columns.Count \ 2)
End With
 
Application.Wait Now + TimeValue("00:00:05")
 
ActiveWindow.Zoom = 100
Application.Goto Target, True
Rng.Activate
With ActiveWindow
     On Error Resume Next
     .ScrollRow = Application.Max(1, .ScrollRow - .VisibleRange.Rows.Count \ 2 + Target.Rows.Count \ 2)
     .ScrollColumn = Application.Max(1, .ScrollColumn - .VisibleRange.Columns.Count \ 2 + Target.Columns.Count \ 2)
End With
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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