Problema con macro che inserisce data/ora . Help!

Anonimo
2021-09-27T16:27:46+00:00

Ho una macro che inserisce data/ora in colonna E , quando inserisco valore manualmente su cella in colonna B . Poi deve ripetere quando inserisco valore su cella in colonna H , su cella in colonna I.

Il mio problema è che il valore nella colonna H viene inserito tramite altra Macro e non manualmente , e non funziona .

Funziona solo se inserisco dati manualmente . Come devo modificare la seconda parte ? grazie

[code]Private Sub Worksheet_Change(ByVal Target As Range)

Dim Rng As Range

Dim xOffsetColumn As Integer

Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), Target)

xOffsetColumn = 3

If Not WorkRng Is Nothing Then

Application.EnableEvents = False

For Each Rng In WorkRng     

If Not VBA.IsEmpty(Rng.Value) Then  

       Rng.Offset(0, xOffsetColumn).Value = Now      

   Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm"    

 Else       

  Rng.Offset(0, xOffsetColumn).ClearContents    

 End If   

Next

Application.EnableEvents = True

End If

Set WorkRng = Intersect(Application.ActiveSheet.Range("H:H"), Target)

xOffsetColumn = 1

If Not WorkRng Is Nothing Then

Application.EnableEvents = False

For Each Rng In WorkRng

    If Not VBA.IsEmpty(Rng.Value) Then    

     Rng.Offset(0, xOffsetColumn).Value = Now    

     Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm" 

    Else    

     Rng.Offset(0, xOffsetColumn).ClearContents   

  End If  

Next Application.EnableEvents = True

End If

End Sub [/code]

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

18 risposte

Ordina per: Più utili
  1. Anonimo
    2021-09-27T17:54:56+00:00

    purtroppo lo stesso problema !

    Comunque nel file esempio basta che vai in foglio2 , seleziona cella sotto ordine e premi il pulsante . Vedrai che la X viene inserita su colonna H , ma non inserisce data/ora come quando lo scrivo manualmente

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Gianfranco55 25,190 Punti di reputazione Moderatore volontario
    2021-09-27T17:50:35+00:00

    Ciao

    questa dovrebbe essere

    quello che vuoi tu

    Private Sub Worksheet_Change(ByVal Target As Range) 
    
    On Error GoTo AAAA 
    
    If Not Intersect(Target, Range("H:H")) Is Nothing Then 
    
    Application.EnableEvents = False 
    
    If Target.Value <> "" Then 
    
    Target.Offset(0, 2) = Format(Now, "dd/mmm/yyyy hh:mm") 
    
    Else 
    
    Target.Offset(0, 2) = "" 
    
    End If 
    
    Application.EnableEvents = True 
    
    End If 
    
    AAAA: Application.EnableEvents = True 
    
    End Sub
    

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2021-09-27T17:47:54+00:00

    Grazie della risposta , l'ho vista dopo aver risposto . Provo subito

    La risposta è stata utile?

    0 commenti Nessun commento
  4. Anonimo
    2021-09-27T17:45:10+00:00

    https://www.dropbox.com/scl/fi/irjy9unsng5fgzivdf47w/ESEMPIO-X-FORUM-CON-MACRO.xlsm?dl=0&rlkey=jjgjl57xrm6qrtfwwr2pma67i

    Esempio.

    Nel foglio 1 se inserite dati su colonna B e H , nessun problema . Ma se inserite dati dal foglio 2 in colonna H non inserisce data/ora su I

    La risposta è stata utile?

    0 commenti Nessun commento
  5. Gianfranco55 25,190 Punti di reputazione Moderatore volontario
    2021-09-27T17:37:06+00:00

    ciao

    ti faccio un esempio

    Private Sub Worksheet_Change(ByVal Target As Range) 
    
    If Not Intersect(Target, Range("h:h")) Is Nothing Then 
    
    Application.EnableEvents = False 
    
    Target.Offset(0, 2) = Format(Now, "dd/mmm/yyyy hh:mm") 
    
    Application.EnableEvents = True 
    
    End If 
    
    End Sub
    

    questo sistema ti intercetta i cambiamenti dovuti a macro

    La risposta è stata utile?

    0 commenti Nessun commento