Notifications
Clear all

UPGRADE EM CÓDIGO que insere data e hora

3 Posts
2 Usuários
0 Reactions
628 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

.
Alguém pode dar uma luz sobre este código??
.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Column = 3 And _
ActiveCell.Offset(columnoffset:=-2) = "" And _
ActiveCell.Offset(columnoffset:=-1) = "" Then
ActiveCell.Offset(columnoffset:=-2) = Date
ActiveCell.Offset(columnoffset:=-1) = Time
End If
End Sub
.
Este código insere data na coluna A e hora na coluna B, ao digitar na coluna C - e não muda este horário ao clicar por engano nas linha anteriores já preenchidas!! ... OK!!
.
O QUE GOSTARIA DE MUDAR NELE ...
.
1) colocar a hora sem AM/PM, ou seja, hora normal (24H) ... 01:00, 10:45, 13:58, 21:00 etc etc!!
2) só inserir a data e hora se digitar algo na coluna C, e não apenas ao dar Enter e o cursor cair na próxima linha, ou clicar nas linhas seguintes, por engano!!
.
PS: veja que cliquei por engano em C12 e C26 e ele já inseriu a data e hora!!
.

 
Postado : 02/07/2017 1:10 pm
(@osvaldomp)
Posts: 857
Prominent Member
 

Veja se ajuda.

Private Sub Worksheet_Change(ByVal Target As Range)
 If Target.Count > 1 Then Exit Sub
 If Target.Column <> 3 Then Exit Sub
 Target.Offset(, -2) = Date
 Target.Offset(, -1) = Time
End Sub

obs. formate a coluna 'B' ~~~> Número / Hora / 13:30

 
Postado : 02/07/2017 2:53 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

.
Já resolvi, é porque tinha salvado em xlsx, e não xlsm)!!
.
Osvaldo, valeu, deu certo!!!
.

 
Postado : 02/07/2017 4:22 pm