Results 1 to 2 of 2

Thread: Excel VBA Macro To Freeze Panes Without Activating WorkSheet

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Excel VBA Macro To Freeze Panes Without Activating WorkSheet

    I want to freeze panes but dont want to activate sheet i.e. in common i use activewindow.freezepanes method but that require sheet to be activated.
    any alternate to that??

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Quote Originally Posted by SP69 View Post
    I want to freeze panes but dont want to activate sheet i.e. in common i use activewindow.freezepanes method but that require sheet to be activated.
    any alternate to that??
    I do not know of any other way to do it, but that doesn't mean you have to leave it as the active sheet nor let the user see it become active. Consider this structure for your code...
    Code:
    Sub FreezePanesOnAnotherSheet()
      Dim CurrentSheet As Worksheet, SheetToFreeze As Worksheet, CellToFreezeAt As String
      ' Store the current sheet so we can go back to it
      Set CurrentSheet = ActiveSheet
      ' Set a reference to the sheet that will have its panes frozen
      Set SheetToFreeze = Worksheets("Sheet2")
      ' Set the address of the cell that will be used to freeze the panes at
      CellToFreezeAt = "C3"
      ' Do not let the user see what is happening
      Application.ScreenUpdating = False
      ' Go to sheet that is to be frozen
      SheetToFreeze.Select
      ' Activate the cell to freeze at
      Range(CellToFreezeAt).Select
      ' Freeze the sheet
      ActiveWindow.FreezePanes = True
      ' Go back to the original sheet
      CurrentSheet.Select
      ' Let the user see again
      Application.ScreenUpdating = True
    End Sub

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2013, 11:32 AM
  2. SQL output from Excel VBA macro
    By goldenbutter in forum Excel Help
    Replies: 3
    Last Post: 05-07-2013, 08:07 PM
  3. Print Nth Worksheet To Mth Worksheet using VBA
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-28-2013, 06:57 PM
  4. Excel 2007 - Freeze Pane without lines
    By irshath in forum Excel Help
    Replies: 1
    Last Post: 02-23-2013, 11:27 PM
  5. Replies: 4
    Last Post: 08-14-2012, 03:17 AM

Tags for this Thread

Posting Permissions

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