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
 
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

Thanks steve the fish. Your code is tested on both works on both CPUs.

/Skovgaard
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,235
Messages
6,123,782
Members
449,123
Latest member
StorageQueen24

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