473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Excel: Code for Ctrl-Home

NeoPa
32,556 Expert Mod 16PB
I would like to know how to select the cell at the top left of the scrolling area of a worksheet. This point is set from the menu by using Window \ Freeze Panes when the required cell is selected. After that point, pressing Ctrl-Home moves the cell selection to that same cell. It is very useful when working with large sets of data where either the rows or the columns (or both of course) have titles at the top (and/or left).

I got the code to select the cell at the last used cell of the range (Ctrl-End) from recording the keystroke into a macro and looking at the resultant code :
Expand|Select|Wrap|Line Numbers
  1. Selection.SpecialCells(xlLastCell).Select
Unfortunately, the code used for Ctrl-Home in the recorded macro is simply to set to the specific range selection :
Expand|Select|Wrap|Line Numbers
  1. Range("B2").Select
PS. If this requires enquiring of various objects then I'm happy to do that. Anything that can help me to duplicate the effect of hitting Ctrl-Home.
Oct 5 '09 #1

✓ answered by ChipR

Expand|Select|Wrap|Line Numbers
  1. Cells(ActiveWindow.Panes(4).ScrollRow, ActiveWindow.Panes(4).ScrollColumn).Select
NeoPa:
It seems that the first scrollable Row and Column from Window or Pane objects always reflects the visibly available screen. This is a nuisance (and I'm still interested in a definitive and non-destructive way to determine the top & left scrollable cells), but for my current purposes I can allow the moving of the visible window to the top left anyway, and thereby get a correct result. Hardly non-destructive, but the best I was able to come up with so far (I still really appreciate the posts) :
Expand|Select|Wrap|Line Numbers
  1. With ActiveWindow
  2.     If .FreezePanes Then
  3.         'Moves the visible pane without setting these values
  4.         'beyond their allowable bounds.
  5.         .ScrollRow = 1
  6.         .ScrollColumn = 1
  7.         Call Cells(RowIndex:=.ScrollRow, _
  8.                    ColumnIndex:=.ScrollColumn).Select
  9.     Else
  10.         Call Range("A1").Select
  11.     End If
  12. End With

7 16636
ADezii
8,834 Expert 8TB
@NeoPa
Hello NeoPa, to select the Cell at the Top Left (ULC) of the Scrolling Area of a Worksheet, you can try:
  1. Programmatically enabling the SCROLL LOCK.
  2. Using SendKeys, send the {HOME} Key (I know I'm redundant!) (LOL)!
  3. I'm sure that you can take it from here.
Oct 5 '09 #2
ChipR
1,287 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Cells(ActiveWindow.Panes(4).ScrollRow, ActiveWindow.Panes(4).ScrollColumn).Select
NeoPa:
It seems that the first scrollable Row and Column from Window or Pane objects always reflects the visibly available screen. This is a nuisance (and I'm still interested in a definitive and non-destructive way to determine the top & left scrollable cells), but for my current purposes I can allow the moving of the visible window to the top left anyway, and thereby get a correct result. Hardly non-destructive, but the best I was able to come up with so far (I still really appreciate the posts) :
Expand|Select|Wrap|Line Numbers
  1. With ActiveWindow
  2.     If .FreezePanes Then
  3.         'Moves the visible pane without setting these values
  4.         'beyond their allowable bounds.
  5.         .ScrollRow = 1
  6.         .ScrollColumn = 1
  7.         Call Cells(RowIndex:=.ScrollRow, _
  8.                    ColumnIndex:=.ScrollColumn).Select
  9.     Else
  10.         Call Range("A1").Select
  11.     End If
  12. End With
Oct 5 '09 #3
NeoPa
32,556 Expert Mod 16PB
Thanks a bunch chaps. That has resolved a long-standing irritation (Jumps around with glee).
Expand|Select|Wrap|Line Numbers
  1. With ActiveWindow
  2.     Call Cells(RowIndex:=.ScrollRow, _
  3.                ColumnIndex:=.ScrollColumn).Select
  4. End With
Chip, your post was enough to tell me where to look. That helped greatly.

ADezii, Thanks for posting. I was really looking for the sort of solution I ended up with, but all suggestions are appreciated.
Oct 5 '09 #4
NeoPa
32,556 Expert Mod 16PB
Hang on. It seems I may not have it exactly right yet. The ActiveWindow (and the panes) seem to refer only to the visible portion of the screen. If I set FreezePanes at B2 and scroll down many pages then the .ScrollRow reflects the top row visible on the screen rather than the top row selectable in the scrolling area. I will look some more.
Oct 5 '09 #5
NeoPa
32,556 Expert Mod 16PB
It seems that the first scrollable Row and Column from Window or Pane objects always reflects the visibly available screen. This is a nuisance (and I'm still interested in a definitive and non-destructive way to determine the top & left scrollable cells), but for my current purposes I can allow the moving of the visible window to the top left anyway, and thereby get a correct result. Hardly non-destructive, but the best I was able to come up with so far (I still really appreciate the posts) :
Expand|Select|Wrap|Line Numbers
  1. With ActiveWindow
  2.     If .FreezePanes Then
  3.         'Moves the visible pane without setting these values
  4.         'beyond their allowable bounds.
  5.         .ScrollRow = 1
  6.         .ScrollColumn = 1
  7.         Call Cells(RowIndex:=.ScrollRow, _
  8.                    ColumnIndex:=.ScrollColumn).Select
  9.     Else
  10.         Call Range("A1").Select
  11.     End If
  12. End With
Oct 5 '09 #6
they this code - it "Ctrl-Home" all sheets and closes all groupings...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Workbook_Open() 
  2.      ' group and Ctrl+Home all sheets at file open
  3.     Dim ws As Worksheet 
  4.     Application.ScreenUpdating = False 
  5.     For Each ws In ActiveWorkbook.Worksheets 
  6.         ActiveWorkbook.Sheets(ws.Name).Activate 
  7.         ActiveWorkbook.Sheets(ws.Name).Outline.ShowLevels RowLevels:=1, ColumnLevels:=1 
  8.         With ActiveWindow 
  9.             .ScrollRow = 1 
  10.             .ScrollColumn = 1 
  11.             If .FreezePanes Then 
  12.                 Call Cells(RowIndex:=.ScrollRow, ColumnIndex:=.ScrollColumn).Select 
  13.             Else 
  14.                 Call Range("A1").Select 
  15.             End If 
  16.         End With 
  17.     Next 
  18.     Sheets("StartSheet").Select 
  19.     Application.ScreenUpdating = True 
  20. End Sub
  21.  
Nov 9 '11 #7
NeoPa
32,556 Expert Mod 16PB
Interestingly, though the last post was fundamentally a duplication of logic and code already posted, it got me to thinking again, and I was able to produce some neater code that handles this. It works on the basis that the .ScrollRow and .ScrollColumn properties of the ActiveWindow cannot be set below the values of the FreezePanes settings. Thus it is not necessary to check for .FreezePanes in the code even. It works in either scenario :
Expand|Select|Wrap|Line Numbers
  1. With ActiveWindow
  2.     .ScrollRow = 1
  3.     .ScrollColumn = 1
  4.     Call Cells(.ScrollRow, .ScrollColumn).Select
  5. End With
Lines #2 and #3 cause the settings to be the minimum allowed in any circumstances. If FreezePanes is set to something then these parameters will be reflected. Otherwise the values set will hold. In either case it will be correct :-)
Nov 11 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
1
by: apgoodb | last post by:
I have a database that I built some functionality to export a query to excel and then do some formatting. After reading a lot of comments it seems I need to use "late binding", because some of the...
9
by: | last post by:
I have a web page written in asp.net that has multiple datagrids on it that would need to be exported to Excel. Each of the datagrids would be a subset of what the datagrid above it was. Thus...
1
by: | last post by:
The following code: Private Sub ClearControls(ByVal ctrl As Control) Dim i As Int32 For i = ctrl.Controls.Count - 1 To 0 Step -1 ClearControls(ctrl.Controls(i))
4
by: Lewis Edward Moten III | last post by:
I have a file that users can download through a web page protected by forms authentication: Download.aspx?ID=45 and within that file ... FileInfo fileToDownload = new FileInfo(fileName);
3
by: | last post by:
Hello, I have a routine in my Windows application that exports the contents of a datagrid to Excel. It is modeled closely after the HowTo example on MSDN: http://tinyurl.com/5g2jm. Depending...
2
by: Jody L. Whitlock | last post by:
I've gotten the COM Addin to work, my problem is this. I need to allow the user to select a range of cells (All in the same column) and then select my addin. My addin needs to pick up this range...
8
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables...
7
by: VoTiger | last post by:
Hi everyone, i am ttrying to find a way to do the copy / paste between an existing excel file and my flexgrid (in runtime application). But the fact is that i don't know how to proceed. The...
9
by: fahadqureshi | last post by:
I am running two visual basic modules in Access and keep coming across an annoying problem. Both the vb modules transfer an excel spreadsheet to an access database but for some reason after the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.