Sub filldateinfo()
' Format the new cells
Range("D2").Select
Selection.Copy
Range("F2:G2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
' Add the formulas to get the year and month
Range("F2").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(MID(RC4,3,1)=""."",MID(RC4,3,1)=""-"",MID(RC4,3,1)=""/""),RIGHT(RC4,4),IF(OR(MID(RC4,5,1)=""."",MID(RC4,5,1)=""-"",MID(RC4,5,1)=""/""),LEFT(RC4,4),""""))"
Range("G2").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(MID(RC4,3,1)=""."",MID(RC4,3,1)=""-"",MID(RC4,3,1)=""/""),LEFT(RC4,2),IF(OR(MID(RC4,5,1)=""."",MID(RC4,5,1)=""-"",MID(RC4,5,1)=""/""),RIGHT(RC4,2),""""))"
' Autofill to the end of the table
Range("F2:G2").Select
Selection.AutoFill Destination:=Range("F2:G8489") 'How do I make this dynamic based on the length of column A?
Range("F2:G8489").Select 'How do I make this dynamic based on the length of column A?
' Replace the formulas with values
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Re-arrange the table
Columns("E:E").Select
Application.CutCopyMode = False
Selection.Cut Destination:=Columns("H:H")
Columns("F:H").Select
Selection.Cut Destination:=Columns("D:F")
Range("A1").Select
End Sub
The length of the table will vary, so I need the autofill to determine it's own "Destination" value based on the length of column A.
Bookmarks