- 13 Jan 2023 às 10:09
#72708
Bom dia.
Veja se era isso:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 10 And Target.Column = 8 Then
If Range("D4") = "" Then Range("D4") = DateSerial(Year(Date), Month(Date), 1): Exit Sub
ThisWorkbook.Names.Add Name:="XDIA", RefersTo:=Day(Range("D4").Value)
ThisWorkbook.Names.Add Name:="XMES", RefersTo:=Month(Date)
ThisWorkbook.Names.Add Name:="XANO", RefersTo:=Year(Date)
If Year(Range("D4")) = Application.Evaluate(ThisWorkbook.Names("XANO").Value) Then
Range("D4") = DateSerial(Application.Evaluate(ThisWorkbook.Names("XANO").Value), _
Application.Evaluate(ThisWorkbook.Names("XMES").Value), _
Application.Evaluate(ThisWorkbook.Names("XDIA").Value) + 1)
Else
ThisWorkbook.Names.Add Name:="XDIA", RefersTo:=1
ThisWorkbook.Names.Add Name:="XMES", RefersTo:=1
ThisWorkbook.Names.Add Name:="XANO", RefersTo:=Year(Date)
Range("D4") = DateSerial(Application.Evaluate(ThisWorkbook.Names("XANO").Value), _
Application.Evaluate(ThisWorkbook.Names("XMES").Value), _
Application.Evaluate(ThisWorkbook.Names("XDIA").Value))
End If
End If
End Sub