Scrolling ??


Posted by Rakla on October 24, 2000 10:08 AM

I am a beginner. I even don' t know if this problem is a scrolling problem or not. I want a code accepting a column number as argument and displaying that column in the middle of the screen. Any help please.



Posted by Ivan Moala on October 25, 2000 1:50 AM

Here is a routine (if I understand you correctly)
that will scroll to the column number and centre
it.........
The column to scroll to and centre is entered in
A1

Sub Scroll_col_middle()
Dim guess
Dim Col
Dim middle

'Check if valid data
If Not Application.WorksheetFunction.IsNumber(Cells(1, 1)) Then
MsgBox "Not a valid column!": End
End If

'Column as Number eg 1,2 etc to view @ A1
Col = Cells(1, 1).Value
'Check if valid column number
If Col > 256 Then MsgBox "Invalid data - Column > 256": End

'have a guess @ where the middle is
guess = 5

On Error Resume Next
GuessAgain:
Application.Goto Cells(1, Col).Offset(0, -guess), True
'Erro occurs if offset is out of range
If Err.Number <> 0 Then guess = guess - 1: Err.Clear: GoTo GuessAgain

'Go back to the Column to View
Cells(1, Col).Select
'Now get the visible range of columns to work out the approx middle
middle = Int(ActiveWindow.VisibleRange.Columns.Count / 2)
'Now we can goto an approx middle
Application.Goto Cells(1, Col).Offset(0, -middle), True
Cells(1, Col).Select

End Sub


Ivan