Solved

Excel VBA, selecting top-left cell in pane

Posted on 2015-02-01
3
140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

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 30

Expert Comment

by:gowflow
ID: 40583646
Your welcome.
gowflow
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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,…
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

751 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