AutoFill Dates with Relative Macro

Bailer

New Member
Joined
Jan 10, 2011
Messages
13
Hi,

I am trying to Automate filling a Column with a correct format date when I download a sheet with dates in the Format 'YYYYMMDD'.

What I am trying to Do:
Insert Column, Insert Formula, Autofill to bottom of Data, Copy Results and Paste as Values, Convert to Excel Date Formatting. Delete Original Column. So Far this is almost working But I have a problem with AutoFilling the Entire Sheet.

Code:
Code:
Sub Dates2()
'
' Dates2 Macro
' 

'
    ' Date Formula
    Selection.EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=DATE(LEFT(RC[1],4),MID(RC[1],5,2),RIGHT(RC[1],2))"
    ActiveCell.Select
    ' Autofill Section
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    ' Good from here
    Selection.Copy
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.NumberFormat = "m/d/yyyy"
    ActiveCell.Offset(0, -1).Columns("A:A").EntireColumn.Select
    Selection.Delete Shift:=xlToLeft
    ActiveCell.Select
    Calculate
    End Sub

How can I change it so that only Cells with Values in them are converted, Without getting #VALUE to the end of the Sheet?

Rgds

Bailer
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,232
Messages
6,123,765
Members
449,121
Latest member
Vamshi 8143

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top