Macro Recorder and Compatibility Problems

Fujirich

Active Member
Joined
May 1, 2003
Messages
320
Hi folks - I have just discovered a compatibility problem with an Excel file I developed for some of my co-workers. I'm hoping for some insight from the experienced folks here at the forum.

I'm running Excel 2003 on a Win XP platform. I recorded a few macros to use as sorting functions, and linked them to buttons on the page. I cleaned up the spurious code (all scrolling related), added screenupdating and protection code, and left everything else as is.

It all works fine on my two computers running XP (one with Excel 2003 and one with Excel 2002.

But, when I run on an older machine with Win 98 and Excel 2000, I get runtime errors.

Here's the code:
Code:
Sub SortButton_Volume()
'
' SortButton_Volume Macro
' Macro recorded 12/20/2003 by Richard J. Herbert
'

'
Application.ScreenUpdating = False
ActiveSheet.Unprotect ("egssales")
    Columns("M:T").Select
    Selection.EntireColumn.Hidden = False
    Range("A19:O318").Select
    Selection.Sort Key1:=Range("F19"), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    Columns("N:S").Select
    Range("N2").Activate
    Selection.EntireColumn.Hidden = True
    Range("G1").Select
ActiveSheet.Protect ("egssales")
Application.ScreenUpdating = True
End Sub

Is there anything here that would cause the runtime problem on the older systems?

Any ideas?

Thanks,
Rich
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Can you specify which line it has a problem with?
 
Upvote 0
Fujirich said:
Hi folks - I have just discovered a compatibility problem with an Excel file I developed for some of my co-workers. I'm hoping for some insight from the experienced folks here at the forum.

I'm running Excel 2003 on a Win XP platform. I recorded a few macros to use as sorting functions, and linked them to buttons on the page. I cleaned up the spurious code (all scrolling related), added screenupdating and protection code, and left everything else as is.

It all works fine on my two computers running XP (one with Excel 2003 and one with Excel 2002.

But, when I run on an older machine with Win 98 and Excel 2000, I get runtime errors.

Here's the code:
Code:
Sub SortButton_Volume()
'
' SortButton_Volume Macro
' Macro recorded 12/20/2003 by Richard J. Herbert
'

'
Application.ScreenUpdating = False
ActiveSheet.Unprotect ("egssales")
    Columns("M:T").Select
    Selection.EntireColumn.Hidden = False
    Range("A19:O318").Select
    Selection.Sort Key1:=.Range("F19"), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    Columns("N:S").Select
    Range("N2").Activate
    Selection.EntireColumn.Hidden = True
    Range("G1").Select
ActiveSheet.Protect ("egssales")
Application.ScreenUpdating = True
End Sub

Is there anything here that would cause the runtime problem on the older systems?

Any ideas?

Thanks,
Rich

Hi,

The following line...

DataOption1:=xlSortNormal

could be removed.

Just a guess here, but I think if you remove that line, you will be able to run the program on earlier versions. Caveat: this was untested, so I could be wrong.

Also, do yourself and others who may have to maintain the code a favor and explicitly determine if you use a header row in your sort.

change

Header:=xlGuess

to

Header:=xlYes
or
Header:=xlNo

This is definitely from the macro recorder, as you cannot choose the "guess" option. This won't make one bit of difference in the execution time, but it will help a bit down the road.

Also, you can clean the code more. Here is an example...

Code:
Sub SortButton_Volume()
'
' SortButton_Volume Macro
' Macro recorded 12/20/2003 by Richard J. Herbert
'

'
Application.ScreenUpdating = False

With ActiveSheet
    .Unprotect ("egssales")

    .Columns("M:T").EntireColumn.Hidden = False
    .Range("A19:O318").Sort Key1:=.Range("F19"), _
        Order1:=xlDescending, _
        Header:=xlYes
    .Columns("N:S").EntireColumn.Hidden = True
    
    .Protect ("egssales")
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Doh!!

Should have included that info before. Here's where the debugger indicates the problem begins:

Code:
    Selection.Sort Key1:=Range("F19"), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal

Thanks!
 
Upvote 0
2k and below won't like
DataOption1:=xlSortNormal

there's no parameter DataOption1 in earlier versions.
 
Upvote 0
Jay Petrulis & starl:

You were exactly right about the DataOption issue.

Once removed, the file ran fine in the older version.

Thanks for the info and prompt responses!

Rich
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

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