Application.ConvertFormula behaves differently

Skovgaard

Board Regular
Joined
Oct 18, 2013
Messages
204
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:
[TABLE="width: 500"]
<tbody>[TR]
[TD]=SUM(A1:A5)
[/TD]
[TD]=SUM(A1:B5)
[/TD]
[/TR]
[TR]
[TD]=SUM(A2:A6)
[/TD]
[TD]=SUM(A2:B6)
[/TD]
[/TR]
[TR]
[TD]=SUM(A3:A7)
[/TD]
[TD]=SUM(A3:B7)
[/TD]
[/TR]
</tbody>[/TABLE]

Correct result of macro (My PC)
[TABLE="width: 500"]
<tbody>[TR]
[TD]=SUM($A1:$A5)
[/TD]
[TD]=SUM($A1:$B5)
[/TD]
[/TR]
[TR]
[TD]=SUM($A2:$A6)
[/TD]
[TD]=SUM($A2:$B6)
[/TD]
[/TR]
[TR]
[TD]=SUM($A3:$A7)
[/TD]
[TD]=SUM($A3:$B7)
[/TD]
[/TR]
</tbody>[/TABLE]

Wrong result of macro (another PC)
[TABLE="width: 500"]
<tbody>[TR]
[TD]=SUM($A1:$A5)
[/TD]
[TD]=SUM($A1:$B5)
[/TD]
[/TR]
[TR]
[TD]=SUM($A3:$A7)
[/TD]
[TD]=SUM($A3:$B7)
[/TD]
[/TR]
[TR]
[TD]=SUM($A5:$A9)
[/TD]
[TD]=SUM($A5:$B9)
[/TD]
[/TR]
</tbody>[/TABLE]

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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,223,992
Messages
6,175,826
Members
452,673
Latest member
LaMiaAvy

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