View Single Post
 
Old 10-22-2011, 11:08 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Scaffold,

You could employ a UDF in the relevant worksheet's code module, coded along the lines of:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static oCell As Range, bVal As Boolean
If oCell Is Nothing Then Set oCell = ActiveCell
If Intersect(oCell, ActiveSheet.Range("A2:C2")) Is Nothing Then Exit Sub
With oCell
  If IsNumeric(.Value) = False Then Exit Sub
  bVal = (CLng(.Value) = Val(.Value))
  If bVal = True Then
    .NumberFormat = "#,##0"
  Else
    .NumberFormat = "#,##0.00"
  End If
End With
End Sub
The above will apply your formatting to any cell in the A2:C2 range. Adjust to suit your needs.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote