F4 Toggle Macro Performance/Tweak

irie267

New Member
Joined
Jul 1, 2012
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hello all--

The macro below allows the user to toggle through the F4 absolute/relative reference feature across a range of selected cells. It's a great macro to have but there are two outstanding issues: 1) if only one cell is selected, the macro takes it upon itself to begin F4 toggling through every formula in the sheet, which is an outcome that isn't desired (would like it to be "turned off" when just one cell is selected), 2) the performance of this macro, even when only a few formulas are selected, is extremely slow. Any assistance in resolving these issues would be greatly appreciated.

VBA Code:
Sub F4_Cycle()
'
' F4_Cycle Macro
'
' Keyboard Shortcut: Ctrl+Shift+/
'
Application.ScreenUpdating = False
Dim inRange As Range, oneCell As Range
Static absRelMode As Long
absRelMode = (absRelMode Mod 4) + 1


Set inRange = Selection.SpecialCells(xlCellTypeFormulas)


If Not (inRange Is Nothing) Then
    For Each oneCell In inRange
        With oneCell
        .FormulaR1C1 = Application.ConvertFormula(.FormulaR1C1, xlR1C1, xlR1C1, absRelMode, oneCell)
        End With
    Next oneCell
End If
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi @irie267 . I hope you are well.

Try this
VBA Code:
Sub F4_Cycle()
  Dim oneCell As Range
  Static absRelMode As Long
 
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual
 
  absRelMode = (absRelMode Mod 4) + 1
  For Each oneCell In Selection
    oneCell.FormulaR1C1 = Application.ConvertFormula(oneCell.FormulaR1C1, xlR1C1, xlR1C1, absRelMode, oneCell)
  Next
 
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hi @irie267 . I hope you are well.

Try this
VBA Code:
Sub F4_Cycle()
  Dim oneCell As Range
  Static absRelMode As Long
 
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual
 
  absRelMode = (absRelMode Mod 4) + 1
  For Each oneCell In Selection
    oneCell.FormulaR1C1 = Application.ConvertFormula(oneCell.FormulaR1C1, xlR1C1, xlR1C1, absRelMode, oneCell)
  Next
 
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
End Sub
This is perfect--thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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