I posted a thread about how to add to an already existing VBA Macro the other day. I basically wanted two columns in my spreadsheet to automatically add the present time with one click of the cell. The macro worked, except for the fact that if I clicked the cell again (even by accident) then it would update the originally entered time to the new, current time. Here was the original macro before the edit:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 6 Then Exit Sub
If Not Intersect(Target, Range("F:H")) Is Nothing Then
With Target
.Value = Time
.NumberFormat = "h:mm AM/PM"
End With
End If
A commenter suggested that I add
If Target <> "" Then Exit Sub
after
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
in order to correct this error. It worked, at first. But then I noticed an error message popping up every time I selected more than one cell at a time. How can I get the same results of keeping the original time locked in even if I click on the cell again, without this error message popping up? Thanks.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 6 Then Exit Sub
If Not Intersect(Target, Range("F:H")) Is Nothing Then
With Target
.Value = Time
.NumberFormat = "h:mm AM/PM"
End With
End If
A commenter suggested that I add
If Target <> "" Then Exit Sub
after
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
in order to correct this error. It worked, at first. But then I noticed an error message popping up every time I selected more than one cell at a time. How can I get the same results of keeping the original time locked in even if I click on the cell again, without this error message popping up? Thanks.