Selecting 'Ctrl+Home' via VBA

GeneralShamu

Board Regular
Joined
Jul 6, 2007
Messages
127
Any ideas? I don't want to select A1 by default given there may subsections within these sheets.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
That Range("A1") sometimes throws code newbies for a loop, because at first glance it appears it might be selecting cell A1, when it is really selecting the first cell in the current region.

Sometimes, to avoid the confusion, I will write it like this:
Code:
    ActiveCell.CurrentRegion.Cells(1, 1).Select
It does the exact same thing as Richard's code, just represented a little differently.
 
Upvote 0
That Range("A1") sometimes throws code newbies for a loop, because at first glance it appears it might be selecting cell A1, when it is really selecting the first cell in the current region.

Sometimes, to avoid the confusion, I will write it like this:
Code:
    ActiveCell.CurrentRegion.Cells(1, 1).Select
It does the exact same thing as Richard's code, just represented a little differently.

So it seems the macro still crashes even with this.

What is happening is that there are plots/graphs on these worksheets and if those are selected then it doesn't actually go to cell A1...
 
Upvote 0
Sometimes, to avoid the confusion, I will write it like this:
Code:
    ActiveCell.CurrentRegion.Cells(1, 1).Select
It does the exact same thing as Richard's code, just represented a little differently.
When going for the first cell (you can't depend of this method for other cells in the range unless you know it's a single column or row), I simply treat the range as a one-dimensional array...

Code:
ActiveCell.CurrentRegion(1).Select
 
Upvote 0
Perhaps:

Code:
If TypeName(Selection)="Range" Then
  ActiveCell.CurrentRegion.Range("A1").Select
Else
  Activesheet.Range("A1").Select
End if

It's not foolproof but should cater for most situations.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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