That macro would have to be inserted specifically into the sheet module of each sheet where you want it to work. If you have 3 sheets, then you will right-click on each sheet tab, VIEW CODE, and paste in the code. So that's 3 modules, 3 copies of that same macro.
Here's a version you can put in the ThisWorkbook module instead, this one macro would then watch ALL sheets and act accordingly on all sheets:
Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Value >= 1000 And Target.Cells.Value < 10000 Then
Target.Cells.NumberFormat = "#"",""###.00"
ElseIf Target.Cells.Value >= 10000 And Target.Cells.Value < 100000 Then
Target.Cells.NumberFormat = "##"",""###.00"
ElseIf Target.Cells.Value >= 100000 And Target.Cells.Value < 1000000 Then
Target.Cells.NumberFormat = "#"",""##"",""###.00"
ElseIf Target.Cells.Value >= 1000000 And Target.Cells.Value < 10000000 Then
Target.Cells.NumberFormat = "##"",""##"",""###.00"
ElseIf Target.Cells.Value >= 10000000 And Target.Cells.Value < 100000000 Then
Target.Cells.NumberFormat = "#"",""##"",""##"",""###.00"
ElseIf Target.Cells.Value >= 100000000 And Target.Cells.Value < 1000000000 Then
Target.Cells.NumberFormat = "##"",""##"",""##"",""###.00"
ElseIf Target.Cells.Value >= 1000000000 And Target.Cells.Value < 10000000000# Then
Target.Cells.NumberFormat = "###"",""##"",""##"",""###.00"
End If
End Sub
Bookmarks