Results 1 to 6 of 6

Thread: Freeze panes in Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Freeze panes in Excel

    I have a macro that copies the contents of sheet A to sheet B. Everything else goes fine but I'm not able to move the freeze panes setting. For example, if there's cell D5 freezed in the sheet A, the macro should set the same cell freezed also in the sheet B.

    I cannot move or copy the whole sheet, which would solve the problem. I can move or copy only the contents of the sheet.

    The 'ActiveWindow.FreezePanes = True' command in the sheet B sets the right setting but to a wrong cell.

    So basically my problem is that I'm not able to find the right cell in the sheet A. If I could do that, it would be easy to choose the same cell in the sheet B and then use the command above.

    Anyone, any ideas? Thanks in advance!

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Freeze panes in Excel

    karhatsu:
    =======

    This may help you ... there are up to 4 panes in a window.
    Code:
    Sub PaneTest()
        MsgBox (ActiveWindow.Panes(1).VisibleRange.Address)
    End Sub
    Be warned that if you reference a pane that does not exist (such as Panes(0)), you get an error message:

    "Run-time error '1004' Application-defined or object-defined error"
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  3. #3
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Freeze panes in Excel

    You'll also want to check out some other related properties of Windows:

    Split, FreezePanes, SplitRow, SplitColumn
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  4. #4
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Freeze panes in Excel

    Here's another helpful hint ...

    MsgBox (ActiveWindow.Panes.Count)
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Resolved Re: Freeze panes in Excel

    Excellent, thanks for your help! This is what I finally used:

    VB Code:
    1. ' test if the freeze panes setting is active
    2. Sheets("original").Select
    3. If (ActiveWindow.Panes.Count > 1) Then
    4.     ' select the freeze panes cell
    5.     ActiveWindow.Panes(ActiveWindow.Panes.Count).VisibleRange.Activate
    6.     ' get the cell range
    7.     freezePanesCell = ActiveCell.Address
    8.     ' set freeze panes in the target sheet
    9.     Sheets("target").Select
    10.     Range(freezePanesCell).Activate
    11.     ActiveWindow.FreezePanes = False ' just in case
    12.     ActiveWindow.FreezePanes = True
    13. End If

  6. #6
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Freeze panes in Excel

    Mostly courtesy of "Definitive Guide to Excel VBA" by Michael Kofler! (a! Apress) Glad it helped you.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width