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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,911
Messages
6,175,334
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