Runtime error 438

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All, I have some code that is working fine on my computer (Office 365) but not on one of my colleague's, (Office 2016). I get a runtime error 438 on this code:
VBA Code:
Sub RotMotPositionActual()

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    Dim lRow_shRotMotPosition As Long: lRow_shRotMotPosition = shRotMotPosition.Range("A" & Rows.Count).End(xlUp).Row + 1
    shRotMotPosition.Range("A2:J" & lRow_shRotMotPosition).ClearContents
    
    shLookup.Range("RotatorFullRange").Copy shRotMotPosition.Range("A2,C2,E2,G2,I2") 'set all rotator positions in shRotMotPosition
    
    'copy Park data to shRotMotPosition
    shRotMotPosition.Range("B2:B722").FormulaR1C1 = _
        "=IF(ISERROR(VLOOKUP(RC[-1],ImportData!R2C2:R39C3,2,FALSE)),"""",VLOOKUP(RC[-1],ImportData!R2C2:R39C3,2,FALSE))"
    shRotMotPosition.Range("B2:B722").Value = shRotMotPosition.Range("B2:B722").Value
    shRotMotPosition.Range("A2") = Round(shDataImport.Range("B40"), 0)
    shRotMotPosition.Range("A3:A722").FormulaR1C1 = "=IF(R[-1]C+1=720,1,R[-1]C+1)"
    shRotMotPosition.Range("A3:A722").Value = shRotMotPosition.Range("A3:A722").Value
    shRotMotPosition.Range("A2:A722").NumberFormat = "0"

    shRotMotPosition.Sort.SortFields.Clear
    shRotMotPosition.Sort.SortFields.Add2 _
        Key:=Range("A1:A721"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
...etc...
The error is in the last two lines. shRotMotPosition is the code name of the worksheet.
...any ideas?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Sometimes arguments for functions change slightly in new versions.

What if you change the "Add2" in this line:
VBA Code:
    shRotMotPosition.Sort.SortFields.Add2 _
        Key:=Range("A1:A721"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
to "Add"?

Does it work then?
 
Upvote 0
Solution
Sometimes arguments for functions change slightly in new versions.

What if you change the "Add2" in this line:
VBA Code:
    shRotMotPosition.Sort.SortFields.Add2 _
        Key:=Range("A1:A721"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
to "Add"?

Does it work then?
It seems to be working. ...strange, the .Add2 line came straight from the Macro recorder. Thanks for your help!
 
Upvote 0
It seems to be working. ...strange, the .Add2 line came straight from the Macro recorder. Thanks for your help!
Yes, that is what I meant. Newer versions of Excel sometimes add a "2" on to the end of some arguments, to allow for expanded functionality (new arguments, etc).
If it is new value that was not available in the older version, it will cause errors.

A good rule of thumb when creating Macros/VBA code to be run on different versions of Excel is that if you write/record it on the computer using the OLDEST version of Excel, it should then work for everybody (as newer versions of Excel can almost always run older code, but older versions of Excel cannot necessarily run code created on newer versions).
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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