Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Oscar Montgomery   on Feb 18 In MS Office Category.

  
Question Answered By: Dixie Jacobs   on Feb 18

Right click on your worksheet tab and view code.
Add the following code to the worksheet VBA editor.
The code runs everytime a value is column B changes, (change to your column)
Formats the cell based on your critria.


Private Sub WorkSheet_Change(ByVal Target As Range)
If Cells(Target.Row, Target.Column) = 0 Then Cells(Target.Row,
Target.Column).NumberFormat = "0"
If Cells(Target.Row, Target.Column) = Empty Then Exit Sub
If Target.Column = 2 Then 'column B
If Cells(Target.Row, Target.Column) > 999 Then 'Add commas to greater
than 999
Cells(Target.Row, Target.Column).NumberFormat = "#,###"
ElseIf Cells(Target.Row, Target.Column) = Int(Cells(Target.Row,
Target.Column)) Then '10.0
Cells(Target.Row, Target.Column).NumberFormat = "0"
Else '10.5
Cells(Target.Row, Target.Column).NumberFormat = "0.0"
End If
End If
End Sub

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Custom Currency Format Or get search suggestion and latest updates.


Tagged: