I have a simple macro at my Excel worksheet, which does some simple calculation. What happens is that for a better user experience I want the macro to run and when it is finished to return to the cell that the user was before he activated the macro, so that the user won't see any change on the screen.
Ok, so that's not to hard:
Dim activeRow As Integer
Dim activeCol As Integer
Sub myCode
activeRow = ActiveCell.Row
activeCol = ActiveCell.Column
' code...
Cells(activeRow, activeCol).Select
End Sub
The problem with the code above is that the line and columns that were visible before the macro runs are not the same on the end, because the macro may have scrolled the worksheet to the left, right, up or down.
For example, you can see the cell E26 on your display either if the first line visible at your worksheet is 15 or 16.
So the question here is how can I know the line and column number that are visible at the user display?
I was wondering that would be something like:
Dim topLine As Integer
Dim bottomLine As Integer
topLine = ActiveWorksheet.GetVisibleGrid.TopLine
bottomLine = ActiveWorksheet.GetVisibleGrid.BottomLine