Excel VB Commands for Control-Home & Control-End without Using SendKeys…

Russ1701

New Member
Joined
Apr 30, 2003
Messages
17
Does anyone know how to add the command to press Control –Home and Control-End without using SendKeys?

As many of you know, using SendKeys tends to play havoc with the NumLock key, turning it off and as a toggle.

I need to be able to go to the highest cell in the upper left outside of the frozen window panes, i.e., within the editable data, not within a frozen pane.

For Control-End, I sim0ply need to be able to go to the lowest lower-right corner cell of the worksheet that has not been used as of yet.

Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This is a very interesting issue. I tried earlier to understand and have control over the screen dimensions and position, and found that this is not straight forward (at least part of it).

I think what you are asking for is the same, unless someone comes up with a better technique.

Meanwhile, you may use the two procedures below to go to the first (Ctrl+Home) and last (Ctrl+End) cells. Copy the code to a Module code window.
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Option Explicit

Sub GotoFirstCell()

    Dim iFirstRow As Integer, iFirstColumn As Integer

    Select Case ActiveWindow.Panes.Count
        Case 1              [COLOR="Green"]'* No frozen panes[/COLOR]
            iFirstRow = 1
            iFirstColumn = 1

        Case 2
            If ActiveWindow.Panes(1).VisibleRange.Rows.Count = 1 Then       [COLOR="Green"]'* Top row frozen[/COLOR]
                iFirstRow = 2
                iFirstColumn = 1
            Else            [COLOR="green"]'* Left column frozen[/COLOR]
                iFirstRow = 1
                iFirstColumn = 2
            End If

        Case 4              [COLOR="green"]'* Frozen rows and columns[/COLOR]
            iFirstRow = ActiveWindow.Panes(1).VisibleRange.Rows.Count + 1
            iFirstColumn = ActiveWindow.Panes(1).VisibleRange.Columns.Count + 1

    End Select
    Cells(iFirstRow, iFirstColumn).Select

End Sub

Sub GotoLastCell()
    Cells.SpecialCells(xlCellTypeLastCell).Select
End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,541
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top