Simple vba question.

vbacoder12

New Member
Joined
Sep 4, 2024
Messages
41
Office Version
  1. 2024
  2. Prefer Not To Say
Platform
  1. Windows
I have an option explicit sub which is running a series of subs one of my last subs is to freeze panes. Some times it freezes the correct amount of panes some times not. Also if I run this outside of the option explicit sub it works fine here is the vba

Sub freezerow
'
' freezerow macro
'
'
With ActiveWindow
.splitcolumn=3
.splitrow=6
End With
ActiveWindow.Freezepanes=TRUE
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Some times it freezes the correct amount of panes some times not.
Do you actually mean the correct "amount" or do you mean the correct position ?
That code is position dependant and depends what cell is visible in the top left corner of the screen when you run the code
 
Upvote 0
Do you actually mean the correct "amount" or do you mean the correct position ?
That code is position dependant and depends what cell is visible in the top left corner of the screen when you run the code
I mean correct position
 
Upvote 0
Give this a try:

VBA Code:
Sub freezerow()
'
' freezerow macro
'
'
    Dim currCell As Range
    
    Application.ScreenUpdating = False
    
    Set currCell = ActiveCell
    Application.Goto Reference:=ActiveSheet.Range("A1"), _
            scroll:=True
    With ActiveWindow
        If .FreezePanes = True Then .FreezePanes = False
            .FreezePanes = True
    End With
    
    Application.Goto Reference:=currCell

End Sub
 
Upvote 0
Give this a try:

VBA Code:
Sub freezerow()
'
' freezerow macro
'
'
    Dim currCell As Range
   
    Application.ScreenUpdating = False
   
    Set currCell = ActiveCell
    Application.Goto Reference:=ActiveSheet.Range("A1"), _
            scroll:=True
    With ActiveWindow
        If .FreezePanes = True Then .FreezePanes = False
            .FreezePanes = True
    End With
   
    Application.Goto Reference:=currCell

End Sub
Does your cursor have to be on a certain cell?
 
Upvote 0
Oops sorry, I added the line in blue.
Rich (BB code):
Sub freezerow()
'
' freezerow macro
'
'
    Dim currCell As Range
   
    Application.ScreenUpdating = False
   
    Set currCell = ActiveCell
    Application.Goto Reference:=ActiveSheet.Range("A1"), _
            scroll:=True
    Application.Goto Reference:=ActiveSheet.Range("D7")
    With ActiveWindow
        If .FreezePanes = True Then .FreezePanes = False
            .FreezePanes = True
    End With
   
    Application.Goto Reference:=currCell ' Optional add --> , scroll:=True

End Sub
 
Upvote 0
Can I ask what issue you were getting with the code in post 7 that required you to add "split column n row" to the code please, just not sure why the code in post 7 wasn't adequate to carry out your request.

Btw, having "Office Version: Prefer Not To Say" in your profile is not very helpful if you are going to be asking questions
 
Upvote 0
Can I ask what issue you were getting with the code in post 7 that required you to add "split column n row" to the code please, just not sure why the code in post 7 wasn't adequate to carry out your request.

Btw, having "Office Version: Prefer Not To Say" in your profile is not very helpful if you are going to be asking questions
Sorry I didn't even know anything about my profile. I had to put it between application.goto reference:=activesheet.range ("a1"),scroll:true

I have another question about another code that isn't working way is thought should I create a new post
 
Upvote 0

Forum statistics

Threads
1,226,105
Messages
6,188,966
Members
453,515
Latest member
maccannix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top