Solved

Excel VBA, selecting top-left cell in pane

Posted on 2015-02-01
3
106 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
Comment Utility
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
Comment Utility
Thank you so much gowflow!  That is exactly what I was looking for.

Thanks again
Alison
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
Your welcome.
gowflow
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now