Application.ConvertFormula behaves differently

Skovgaard

Board Regular
Joined
Oct 18, 2013
Messages
197
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have below macro, which works on my PC. On another PC, the same code behaves differently.

Any ideas why this is different, we both run Excel 2016?

Code:
Sub setFixedCol()
'Hotkey: Ctrl + Shift + U
Dim c As Range
For Each c In Selection
    If c.HasFormula Then
        c.Formula = Application.ConvertFormula(c.Formula, xlA1, xlA1, 3)
    End If
Next
End Sub

Cells before run of macro:
=SUM(A1:A5)
=SUM(A1:B5)
=SUM(A2:A6)
=SUM(A2:B6)
=SUM(A3:A7)
=SUM(A3:B7)

<tbody>
</tbody>

Correct result of macro (My PC)
=SUM($A1:$A5)
=SUM($A1:$B5)
=SUM($A2:$A6)
=SUM($A2:$B6)
=SUM($A3:$A7)
=SUM($A3:$B7)

<tbody>
</tbody>

Wrong result of macro (another PC)
=SUM($A1:$A5)
=SUM($A1:$B5)
=SUM($A3:$A7)
=SUM($A3:$B7)
=SUM($A5:$A9)
=SUM($A5:$B9)

<tbody>
</tbody>

As you can see, on the second PC, it jumps a row...!?

/Skovgaard
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Id be surprised if its the code. Try it on a single cell. Does that change? Are there hidden rows? Are the initial formulas really the same as yours?
 
Upvote 0
Id be surprised if its the code. Try it on a single cell. Does that change? Are there hidden rows? Are the initial formulas really the same as yours?

We have both tested on the same example and with two different results. So no hidden rows, the formulas are exactly the same, as I wrote them. So I also think, that this is very strange.
Can there be a setting somewhere, that can influence on this?
 
Upvote 0
Hi Skovgaard,

Is it just 1 workbook open?
If yes, and it is a setting of some sort, one quick way to check is to create a bunch of Debug.Print Application.XXSetting to see what turns up True ur False.

When I do this, I copy straight from the VBA Ref under Application and paste to match destination in Excel, then create a column of Debug.Print then a column of "Application." (w/o quotes), then concat the 3 columns in correct order, copy and paste values, then copy into VBE. If done correctly it only takes about 1 min.

Any Application property that isn't Bool can simply be excised or commented out if the sub hits a snag.

Compare the results from both CPUs.
 
Upvote 0
Oh, one other possibility is that one of you is running an Insider edition. Maybe you could share some screenshots so I can see the layouts?
 
Upvote 0
Hi Skovgaard,

Is it just 1 workbook open?
If yes, and it is a setting of some sort, one quick way to check is to create a bunch of Debug.Print Application.XXSetting to see what turns up True ur False.

When I do this, I copy straight from the VBA Ref under Application and paste to match destination in Excel, then create a column of Debug.Print then a column of "Application." (w/o quotes), then concat the 3 columns in correct order, copy and paste values, then copy into VBE. If done correctly it only takes about 1 min.

Any Application property that isn't Bool can simply be excised or commented out if the sub hits a snag.

Compare the results from both CPUs.

Hi Gravanoc,

The Macros are being stored in another workbook, so 2 workbooks are open at the same time. The workbook with the macros are hidden and open automatically, when Excel is opened.
But this is the same on both CPUs.

I'm uncertain how to create a bunch of Debug.Print. And the two CPUs are not on same location :)

/Ulrik
 
Upvote 0
How can you be certain what 'Selection' is when its run then?

Because we have tested the same spreadsheet, and when I run the macro, it doesn't matter whether I select one cell, two cells or all six cells, It works as it should.

/Skovgaard
 
Upvote 0
This is the same without the loop. Whats that do?

Code:
On Error Resume Next
With Selection.SpecialCells(xlCellTypeFormulas)
    .Formula = Application.ConvertFormula(.Formula, xlA1, xlA1, 3)
End With
 
Upvote 0
If you are still having problems, you could upload your workbook and I will see if the issue occurs on my cpu.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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