worksheet change question

T

Tonso

I want to be able to enter a time, using "." instead of ":", so that
when I enter the number, then press "Enter", the number changes from,
say, 13.27.33 to 13:27:33. But I am having to reselect the cell to get
it to change. What is wrong with my code?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Selection.Replace What:=".", Replacement:=":", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False
Selection.NumberFormat = "h:mm:ss"
End Sub

Thanks,

Tonso
 
G

Gord Dibben

Wrong event. Try this one.

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Replace What:=".", Replacement:=":", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Target.NumberFormat = "h:mm:ss"
End Sub


Gord Dibben MS Excel MVP
 
T

Tonso

Wrong event.  Try this one.

Private Sub Worksheet_Change(ByVal Target As Range)
    Target.Replace What:=".", Replacement:=":", LookAt:=xlPart,_
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Target.NumberFormat = "h:mm:ss"
End Sub

Gord Dibben  MS Excel MVP




- Show quoted text -

As always Gord, thanks so much. it works perfectlty!!!

Tonso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top