Cambiar de texto a fecha y agregar columnas
Estuve haciendo un código para pasar de esto:

a esto:

Pero sinceramente me quedó un código muy largo e inentendible, quisiera saber si alguien me puede ayudar a pensar de otra manera ese código y que quede más corto.
Acá mi solución:
Sub fecha_mes_año()
Dim inicial As Range
Set inicial = Range("E1")
inicial.Offset(0, 1).EntireColumn.Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
inicial.EntireColumn.Select
Selection.TextToColumns Destination:=inicial, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="-", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
TrailingMinusNumbers:=True
inicial.Value = "Año"
inicial.Offset(0, 1).Value = "Mes"
inicial.Offset(0, 2).EntireColumn.Delete
Range(inicial, inicial.Offset(0, 1)).EntireColumn.NumberFormat = "General"
Dim Rng As Range: Set Rng = Range(inicial.Offset(0, 1), inicial.End(xlDown).Offset(0, 1))
Dim cll As Range
For Each cll In Rng
If cll.Value = 1 Then
cll.Value = "Enero"
ElseIf cll.Value = 2 Then
cll.Value = "Febrero"
ElseIf cll.Value = 3 Then
cll.Value = "Marzo"
ElseIf cll.Value = 4 Then
cll.Value = "Abril"
ElseIf cll.Value = 5 Then
cll.Value = "Mayo"
ElseIf cll.Value = 6 Then
cll.Value = "Junio"
ElseIf cll.Value = 7 Then
cll.Value = "Julio"
ElseIf cll.Value = 8 Then
cll.Value = "Agosto"
ElseIf cll.Value = 9 Then
cll.Value = "Septiembre"
ElseIf cll.Value = 10 Then
cll.Value = "Octubre"
ElseIf cll.Value = 11 Then
cll.Value = "Noviembre"
ElseIf cll.Value = 12 Then
cll.Value = "Diciembre"
End If
Next cll
End Sub
1 Respuesta
Respuesta de Dante Amor
1
