Convert macro

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,051
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
This was recorded
Code:
 Sheets("Sheet1").Select
    Cells.Select
    Selection.Clear
    Range("A1").Select
    With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
    End With
    ActiveWindow.FreezePanes = True
    Columns("A:A").ColumnWidth = 36
    Columns("B:B").ColumnWidth = 36

Is it possible to execute this (re write it) without using Select or Active Window ?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I don't believe so, but what is the problem with using activewindow ??
Code:
Sub MM1()
Sheets("Sheet1").Activate
With ActiveSheet.Cells
    .Clear
    .Columns("A:A").ColumnWidth = 36
    .Columns("B:B").ColumnWidth = 36
End With
With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
    .FreezePanes = True
End With
End Sub
 
Upvote 0
Just to use VBA without relying on anything else. That is, let the code control / do everything.
Stepping through shows the selections being made, it shouldn't need to do that.
I liked your changes.
Thanks.
 
Upvote 0
Code:
Sheets("Sheet1").Activate
Cells.Clear
Columns("A:B").ColumnWidth = 36
Range("A1").Select
With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
    .FreezePanes = True
End With
 
Upvote 0
Thanks Footoo.
Is it true = if you select something in code, you can't de-select it. You can only select something else?
 
Upvote 0
Stepping through shows the selections being made, it shouldn't need to do that.
In that case simply add...

Code:
Sub MM1()
[color=red]application.screenupdating=false[/color]
Sheets("Sheet1").Activate
With ActiveSheet.Cells
    .Clear
    .Columns("A:A").ColumnWidth = 36
    .Columns("B:B").ColumnWidth = 36
End With
With ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
    .FreezePanes = True
End With
[color=red]application.screenupdating=true[/color]
End Sub
 
Upvote 0
Thanks Footoo.
Is it true = if you select something in code, you can't de-select it. You can only select something else?
I don't know. I am using 2016 in which the de-select feature is not available.
Why not try it?
 
Last edited:
Upvote 0
Thanks Michael, that's one way round it!
footoo, I've got 2016 as well, didn't know there was a de-select.
 
Upvote 0
Holding down the CTRL key and selcting the cells to deselect will work.....but there must always be at least 1 active cell !
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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