cmefly
Well-known Member
- Joined
- May 13, 2003
- Messages
- 683
Hi,
i'm trying to create a macro that works in the background of a worksheet.
I have 2 columns, A and B.
Column A has a pull down menu where the user can choose from 3 letters - A, B, or C.
Column B is an input cell where the user types in numeric value.
What i'm looking for is IF the user chooses A, then the value in column B should be formatted to 2 DECIMAL PLACES.
IF the user chooses B, then the value in column B should be formatted to 4 DECIMAL PLACES.
F the user chooses C, then the value in column B should be formatted to 5 DECIMAL PLACES.
this is what i have but i doesn't work properly b/c it keeps looping.....
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim z As Integer
For z = 1 To 907 ' number of rows i have
If Range("a" & z).Value = "A" Then
Range("b" & z).Select
Selection.NumberFormat = "0.00"
End If
If Range("a" & z).Value = "B" Then
Range("b" & z).Select
Selection.NumberFormat = "0.0000"
End If
If Range("a" & z).Value = "C" Then
Range("b" & z).Select
Selection.NumberFormat = "0.00000"
End If
Next z
End Sub
i'm trying to create a macro that works in the background of a worksheet.
I have 2 columns, A and B.
Column A has a pull down menu where the user can choose from 3 letters - A, B, or C.
Column B is an input cell where the user types in numeric value.
What i'm looking for is IF the user chooses A, then the value in column B should be formatted to 2 DECIMAL PLACES.
IF the user chooses B, then the value in column B should be formatted to 4 DECIMAL PLACES.
F the user chooses C, then the value in column B should be formatted to 5 DECIMAL PLACES.
this is what i have but i doesn't work properly b/c it keeps looping.....
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim z As Integer
For z = 1 To 907 ' number of rows i have
If Range("a" & z).Value = "A" Then
Range("b" & z).Select
Selection.NumberFormat = "0.00"
End If
If Range("a" & z).Value = "B" Then
Range("b" & z).Select
Selection.NumberFormat = "0.0000"
End If
If Range("a" & z).Value = "C" Then
Range("b" & z).Select
Selection.NumberFormat = "0.00000"
End If
Next z
End Sub