Solved

Lock view  it accordingly

Posted on 2012-12-26
3
414 Views
Last Modified: 2012-12-26
Hello All,

I have a VBA issue. Is it possible to toggle freeze-rows at the column headers of two data sets in the same sheet? Like:
 if I put 1 in cell K2, then freeze panes happens at D5.
if I put 2 in cell K2, then freeze panes happens at D22.

Thank you
R
lockFreezeIt.xlsx
0
Comment
Question by:Rayne
[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 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38721012
Hi, Rayne.

Please see attached. The code is...
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCell As Range
Dim xChoice

If Intersect(Target, Me.Range("K2")) Is Nothing Then Exit Sub

xChoice = Me.Range("K2")
If (xChoice <> 1 And xChoice <> 2) Then Exit Sub    'Ignore values other than "1" and "2".

Application.ScreenUpdating = False
    
    Set xCell = ActiveCell                          'Remember where we are.
    
    ActiveWindow.FreezePanes = False
    If xChoice = 1 Then
        Me.Range("D5").Select
    Else
        Me.Range("D22").Select
    End If
    ActiveWindow.FreezePanes = True
    
    xCell.Select                                    'Back to where we came from.

Application.ScreenUpdating = True

End Sub

Open in new window

Regards,
Brian.lockFreezeIt-V2.xlsm
0
 

Author Comment

by:Rayne
ID: 38721599
Thanks Brian
:)
Thats great
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38722177
Thanks, Rayne.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

761 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