scroll window to display selected cell in visible area?
Try something like this:
Sub AAAC()
Dim Target As Range, rng As Range
Set Target = Worksheets("Sheet3").Range("P70")
Application.Goto Target, True
Set rng = ActiveWindow.VisibleRange
If Intersect(rng, ActiveCell) Is Nothing Then
ActiveWindow.ScrollRow = _
Target.Offset(-rng.Rows.Count + 1).Row
Set rng = ActiveWindow.VisibleRange
If Intersect(rng, ActiveCell) Is Nothing Then
ActiveWindow.ScrollColumn = _
Target.Offset(0, -rng.Columns.Count + 1).Column
End If
End If
End Sub
--
Regards,
Tom Ogilvy
"Kate" wrote in message
...
Hi, does anyone have any good code for positioning the
window so that a cell which was selected via code will be in
the visible area? I have set the scrollarea for each tab on
my sheet, so I can't use the application.goto method to
position the selected cell at the upper left, if it's the
last cell in the scroll area range. This is part of a
validity check routine that looks for missing data. I'm
telling the user that the cursor is located where the
problem is, but it is often off-screen!! I'm using Excel
2003 sp1.
Thanks in advance,
Kate
|