ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to display the cell it goes to at the centre of the monitor screen (https://www.excelbanter.com/excel-programming/368055-how-display-cell-goes-centre-monitor-screen.html)

cyberdude

How to display the cell it goes to at the centre of the monitor screen
 
Hi,

After I have entered a value, I go to the cell holding the value by the

command Range.("cell_address").select to check what value I have
entered. It always goes to the cell I selected. It sometimes display
the target cell at the centre of the monitor screen but sometimes it
doesn't. How can I always make it display the target cell at the
centre of the monitor screen or somewhere as near it as possible?
Thank you.


David


keepITcool

How to display the cell it goes to at the centre of the monitor screen
 
David,

following seems to work...

Sub Test()
Centre Range("z123")
End Sub


Sub Centre(r As Range)
Dim x&, y&
Dim l&, u&
Application.ScreenUpdating = False
Application.Goto r, True

With ActiveWindow
With .VisibleRange
x = .Left - .Width / 2 + ActiveCell.Width
y = .Top - .Height / 2 + ActiveCell.Height
l = .Columns.Count
u = .Rows.Count
End With

Do While l 0 And x 0 And .VisibleRange.Left x
l = l - 1
.SmallScroll ToLeft:=1
Loop
Do While u 0 And y 0 And .VisibleRange.Top y
u = u - 1
.SmallScroll Up:=1
Loop

End With
Application.ScreenUpdating = True

End Sub


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


cyberdude wrote in
groups.com

Hi,

After I have entered a value, I go to the cell holding the value by
the

command Range.("cell_address").select to check what value I have
entered. It always goes to the cell I selected. It sometimes display
the target cell at the centre of the monitor screen but sometimes it
doesn't. How can I always make it display the target cell at the
centre of the monitor screen or somewhere as near it as possible?
Thank you.


David



All times are GMT +1. The time now is 09:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com