I am trying to create a macro that cycles through different formats by simply pressing its corresponding shortcut. The code I created is the following:
Option Explicit
Sub FormatCycle()
'
' FormatCycle Macro
'
' Keyboard Shortcut: Ctrl+Shift+E
'
If Selection.NumberFormat = "General" Then
Selection.NumberFormat = "#,##0.00_);(#,##0.00)"
ElseIf Selection.NumberFormat = "#,##0.00_);(#,##0.00)" Then
Selection.NumberFormat = "0.00%_);(0.00%)"
ElseIf Selection.NumberFormat = "0.00%_);(0.00%)" Then
Selection.NumberFormat = "#,##0.00""x"";(#,##0.00""x"")"
ElseIf Selection.NumberFormat = "#,##0.00""x"";(#,##0.00""x"")" Then
Selection.NumberFormat = "General"
Else
Selection.NumberFormat = "General"
End If
End Sub
Everything works fine except for the second type of format with negative values (i.e. (#,##0.00)). When I use this format on its own, e.g. by custom formatting a generic cell, it does its job and displays the negative number in brackets. However, within the macro, when I make it run it shows the number with the "general" format, e.g. -12.00 instead of (12.00).
What I am getting wrong?