tiene algunos subs en ejecución que apuntan a tomar la fecha del 22/11/2004 y cambiarla al 11/04/2022. Este formato de fecha actualizado se pegará en una hoja nueva hasta que se llegue a la fila final según la Columna A. Actualmente hay un error de depuración y no es el más familiarizado con VBA o la depuración en general, por lo que agradecería cualquier ayuda, ¡gracias!
Sub TakeDate() Sheets("Data Dump").Activate Dim TakeDate As Date ' Two different versions from LM ' First is 2006-14-21 for June 14 2021 ' Second is 6/14/21 for June 14 2021 If VarType(Range("G4").Value) = 7 Then TakeDate = Format(Range("G4").Value, "yyyy/mm/dd") ElseIf InStr(Range("G4").Value, "-") <> 0 Then Dim strFull As String strFull = Range("G4").Value Dim month As String Dim dd As String Dim yy As String Dim dateFull As String month = Split(strFull, "-")(0) month = Right(month, 2) Select Case month Case Is = "01" month = "January" Case Is = "02" month = "February" Case Is = "03" month = "March" Case Is = "04" month = "April" Case Is = "05" month = "May" Case Is = "06" month = "June" Case Is = "07" month = "July" Case Is = "08" month = "August" Case Is = "09" month = "September" Case Is = "10" month = "October" Case Is = "11" month = "November" Case Is = "12" month = "December" End Select dd = Split(strFull, "-")(1) yy = Split(strFull, "-")(2) TakeDate = month + " " + yy + " " + dd MsgBox TakeDate Else TakeDate = Format(Range("G4").Value, "yyyy/mm/dd") End If End Sub Sub FindLastCell() ' Returns the last row # of an inputted column ' Used to reference where it will auto-fill to Dim cell As Long Dim FindLastCell As Long Dim lastCell As Long With Application.Worksheets("Daily Cumulations") lastCell = .Cells(.Rows.Count, cell).End(xlUp).row End With FindLastCell = lastCell ' Just learned you can use these below but the above works ' Columns("A").End(xlDown).Select ' Columns("A").End(xlDown).Offset(1,0).Select End Sub Sub FillDate() ' Input date ' Will auto-fill up to the last value of A col Dim repDate As Date Dim lastCell As String Dim userIn As Date lastCell = FindLastCell("A") Columns("G").End(xlDown).Offset(1, 0).Select 'userIn = InputBox("Enter Date MMMM DD YYYY") Range(Selection, "G" & FindLastCell("I")).Value = repDate End SubPodría usar una fórmula: =DATE(2000+DAY(A1),MONTH(A1),MOD(YEAR(A1),100))
O como una función pública, lo siguiente debería funcionar
Public Function ReverseDate(Src As Range) As String If Src.Cells.Count <> 1 Then Exit Function Dim dDate As Long: dDate = CDate(Src.Value) ReverseDate = DateSerial(2000 + Day(dDate), Month(dDate), Year(dDate) Mod 100) End Function