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

C

cyberdude

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
 
K

keepITcool

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top