View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
scott23 scott23 is offline
external usenet poster
 
Posts: 15
Default change event question

Hi - i have the following worksheet macro.

It does 2 things
1) Makes anything typed in cell E29 into upper case
2) If a change in e29 takes place ... it changes the corresponding
cells below into the proper format.

The only problem is that anytime i type anywhere on the worksheet and
then press enter - its bringing me to cell E29. How do eliminate that
so it only has a change event when THAT cell (E29) is changed, and NOT
any cell on the sheet ?

Thanks
scott


Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo ws_exit
Range("f20:f20").Select
Dim Rng As Range
For Each Rng In Selection.Cells
If Rng.HasFormula = False Then
Rng.Value = UCase(Rng.Value)
End If
Next Rng
With Target
If .Column = 6 Then
If ((.Row = 20 And .Row <= 20)) Then
Select Case Target.Value
Case "ES": FormatCells Target,
"###0.00;[Red]###0.00"
Case "NQ": FormatCells Target,
"###0.00;[Red]###0.00"
Case "ER2": FormatCells Target,
"###0.00;[Red]###0.00"
Case "YM": FormatCells Target, "###0;[Red]####"
Case "ZB": FormatCells Target, "# ??/32;[Red]#
??/32"
Case "EUR": FormatCells Target,
"0.0000;[Red]0.0000"
Case "JPY": FormatCells Target, "0.0000"
Case "GE": FormatCells Target,
"00.000;[Red]00.000"
Case "CAD": FormatCells Target,
"00.000;[Red]00.000"
Case "YG": FormatCells Target,
"###0.00;[Red]###0.00"
Case "YI": FormatCells Target, "0.000;[Red]0.000"
Case "SPY": FormatCells Target, "###.00"
Case "QQQ": FormatCells Target, "###.00"
End Select
End If
End If
End With



ws_exit:
Application.EnableEvents = True
End Sub




Private Sub FormatCells(Rng As Range, format As String)
Rng.Cells(1, 1).NumberFormat = format
Rng.Cells(1, 2).NumberFormat = format
Rng.Cells(1, -1).NumberFormat = format
Rng.Cells(1, -2).NumberFormat = format
Rng.Cells(0, 0).NumberFormat = format
Rng.Cells(-0, 1).NumberFormat = format
Rng.Cells(0, 2).NumberFormat = format
Rng.Cells(0, 3).NumberFormat = format
Rng.Cells(0, -1).NumberFormat = format
Rng.Cells(0, -2).NumberFormat = format
Rng.Cells(0, -3).NumberFormat = format






End Sub