JLatham replied to RoRo123
21-Nov-09 08:41 AM

On the offchance that you do end up going with the VBA solution, I have
modified the code based on your 2nd posting. This will first check to make
sure that only one cell changed (so you can use [Del] without fear), and that
the changed cell was in a row from 3 to 369, then it goes on as before to
check if the change was in columns C, D or E.
I could have used INTERSECT() easily with your setup since C3:E369 is an
easily defined range, but I elected to stick with the Select Case to give you
some flexibility in the future in case you insert columns between C and D or
D and E (you would have to change the code just a little), or need to test other
columns in the same manner.
I am presuming that having the sheet locked will not affect things, since the
cells we are examining are presumably being typed into by a user, so those
individual cells are not locked. If that is not the case, let me know and we
can add a couple of lines of code to deal with unprotecting and reprotecting
the sheet.
Here is the new code:
Private Sub Worksheet_Change(ByVal Target As Range)
'check for changes in columns C, D or E
'between rows 3 and 369 (inclusive) and if the entry
'in the cell changed, replace commas or colons with periods.
'
'can be modified to check any number of columns
'
Dim newEntry As String
'validate the change as:
' #1 - a single cell, so if you [Del] a bunch, nothing happens
' #2 - change took place in rows 3:369
If Target.Cells.Count > 1 Then
Exit Sub ' multiple cells selected
End If
If Target.Row < 3 Or Target.Row > 369 Then
Exit Sub ' not in rows 3 through 369
End If
Application.EnableEvents = False ' prevent re-entry
newEntry = Target.Text
Select Case Target.Column
Case Is = 3, 4, 5 ' columns C, D or E
newEntry = Replace(newEntry, ",", ".")
newEntry = Replace(newEntry, ":", ".")
Case Else
'do nothing
End Select
Target.NumberFormat = "General"
Target.Value = newEntry
Application.EnableEvents = True ' for next time
End Sub