Solved

Excel VBA, selecting top-left cell in pane

Posted on 2015-02-01
3
123 Views
Last Modified: 2016-02-10
Hi

I would appreciate help with VBA that I could use to select the top left hand cell in a pane (my worksheet has frozen panes).
I have tried the following, however this does not deal with the situation where the first column in the pane is hidden.  So if the pane starts at column G, but columns G - J are hidden I would like the selection to be made with respect to column K.  Using the VBA below the selection is made in column G.

With ActiveWindow
    .ScrollRow = 1
    .ScrollColumn = 1
    Call Cells(RowIndex:=.ScrollRow, ColumnIndex:=.ScrollColumn).Select
End With

Open in new window


Many thanks in advance
Alison
0
Comment
Question by:alisonthom
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 40582860
Yes you need to try this

Sub SelectTopLeft()
Dim cCell As Range

With ActiveWindow
    .ScrollRow = 1
    .ScrollColumn = 1
    Set cCell = Cells(RowIndex:=.ScrollRow, ColumnIndex:=.ScrollColumn)
    If cCell.EntireColumn.Hidden Or cCell.EntireRow.Hidden Then
        
        Do
            If cCell.EntireColumn.Hidden Then
                Set cCell = cCell.Offset(0, 1)
            End If
            
            If cCell.EntireRow.Hidden Then
                Set cCell = cCell.Offset(1, 0)
            End If
        
        Loop Until cCell.EntireColumn.Hidden = False And cCell.EntireRow.Hidden = False
        
        cCell.Select
        
    Else
        Cells(RowIndex:=.ScrollRow, ColumnIndex:=.ScrollColumn).Select
    End If
End With
End Sub

Open in new window


gowflow
0
 

Author Comment

by:alisonthom
ID: 40582877
Thank you so much gowflow!  That is exactly what I was looking for.

Thanks again
Alison
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40583646
Your welcome.
gowflow
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question