VBA Code for "CTRL+HOME/END"?

Lazarus416

Board Regular
Joined
Feb 20, 2013
Messages
103
Is there a VBA code that I can use to mimic the ctrl+home/end function? When I record a macro manually and use those functions, it inserts code to select a specific cell rather than code to "goto the 1st cell" or "goto the last cell". Thanks in advance for any info.

Laz
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I think Ctrl+Home always moves to cell A1 assuming it's visible. If A1 is not visible, then this moves to the 1st visible cell.
Cells.SpecialCells(xlCellTypeVisible)(1).Select

This is equivalent to Ctrl+End
Cells.SpecialCells(xlCellTypeLastCell).Select
 
Last edited:
Upvote 0
Appreciate it. I'll give that one a try.

Oh...one more related question, is there a VBA equivalent to ctrl+shift+end? As I sit here and think about it, that's really the one I need. For selecting all of the (variable sized) worksheet so that I can covert it to a table as part of the macro.
 
Last edited:
Upvote 0
This selects contiguous data starting from A1
Range("A1").CurrentRegion.Select

Or this...
Range("A1", Cells.SpecialCells(xlCellTypeLastCell)).Select
 
Upvote 0
This selects contiguous data starting from A1
Range("A1").CurrentRegion.Select

Or this...
Range("A1", Cells.SpecialCells(xlCellTypeLastCell)).Select

Thanks Alpha, the first one worked great (once I figured out how to stick in the table conversion code). You just made my life MUCH easier.

For anyone who needs the full conversion code to convert a dynamic range into a table, here it is:

Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = _
        "Table1"
    Range("Table1[#All]").Select
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium16"

(The tablestyle can be whatever you want...)
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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