Excel 2010 vs Excel 2019 Error

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I ran into an code error with my 2010 excel. Apparently Excel 2019 has support for some code that Excel 2010 does not support. Case in point…The below line of code causes an error in Excel 2010 but not in Excel 2019. How can I fix this?

.PivotFields("Exit Date").AutoGroup



VBA Code:
With Pvt

.PivotFields("Exit Date").Orientation = xlRowField

.PivotFields("Exit Date").AutoGroup

.AddDataField Pvt.PivotFields("Profit/Loss ($)"), "Sum of Profit/Loss ($)", xlSum

.PivotFields("Sum of Profit/Loss ($)").NumberFormat = "$#,##0.00;[Red]$-#,##0.00"

End With
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
@Av8tordude .... We cannot expect "forward compatibility" in old versions. But we can "expect" (hope for) "backward compatibility" in new versions.

My approach is to implement VBA code in the oldest version of Excel that I want my VBA code to work in. The hope is: it will also work in any future version of Excel.

That said, MSFT is renowned for breaking backward compatibility. Case in point: the introduction of "@" syntax for formulas in recent versions of Excel.

If necessary, you might try to determine the Excel version programmatically, and use conditional compilation (#IF) to implement multiple versions of VBA code (sigh).

The following suggests one method: [SOLVED] How to identify my version of VBA .

I have not vetted the information.

I think Application.Version provides a more direct method. But I have not looked for a webpage that describes all of its values, especially a list that is up-to-date.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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