VBA Code to Macro issues - Activate method of range class failed

LAXJESTER

New Member
Joined
Aug 17, 2010
Messages
2
I have this code that I cut and paste into a workbook, run and then save and close in a macro free workbook. I am trying to set this up as a macro in my personal file to share but keep getting the error above after the activate line. Any ideas as to why I cannot simply just put this as a macro?

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Sub FreezePains()
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    Dim Sh AsWorksheet
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    Application.ScreenUpdating = False
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    For Each Sh InThisWorkbook.Worksheets
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]        With Sh
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]            .Activate
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]            .Range("C6").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]        End With
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]        ActiveWindow.FreezePanes= True
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    Next Sh
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    ThisWorkbook.Worksheets(1).Activate
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    Application.ScreenUpdating = False
[/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If you put that in your Personal workbook and want it to work on whatever workbook is active, then change ThisWorkbook (2 places in the sub) to ActiveWorkbook.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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