On the offchance that you do end up going with the VBA solution, I've
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'd have to change the code just a little), or need to test other
columns in the same manner.
I'm 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's 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's 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
RoRo123 said:
Sorry. I guess stating "all" possible errors was a bit of a stretch. How
will the code change knowing that the applicable cells are C3:C369, D3
369
and E3:E369. Also, will it affect any Locked cells?
--
RGS
JLatham said:
Well, I don't know about eliminating all possible error entries since humans
seem to have an almost infinite capacity for screwing up a typed entry, but...
This code will test entries and replace commas and colons with a period
which should help most of the time.
To put the code to work, open your workbook, go to the time entering sheet
and right-click on its name tab and choose [View Code] from the list that
appears. Copy the code below and paste it into the code module presented to
you. Make any change needed to get it to work in the correct column(s).
Close the VB Editor and give it a try.
Private Sub Worksheet_Change(ByVal Target As Range)
'check for changes in a column 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
Application.EnableEvents = False ' prevent re-entry
newEntry = Target.Text
Select Case Target.Column
Case Is = 3 ' column C
newEntry = Replace(newEntry, ",", ".")
newEntry = Replace(newEntry, ":", ".")
Case Else
'do nothing
End Select
Target.NumberFormat = "General"
Target.Value = newEntry
Application.EnableEvents = True ' for next time
'
'if you wish to check multiple columns, then
'just change the initial Case Is = statement to
'include all column numbers, as this example
'for columns C, G and R
' Case Is = 3, 7, 18
End Sub
:
Errors with Hrs. entry by employees. Occasional keying errors such as colons
(8:00), commas (8,00), etc. How do I set up a validation that eliminates all
possible error entries other than regular hr. entries with 2 decimal places,
and gives a pop-up error message? We are using Excel 2003.