Macro to format date and filldown

tj4birdie

Board Regular
Joined
Jul 2, 2009
Messages
60
Hi guys - here's my issue. Creating a Macro to convert a standard 8digit numeric into date format per below. What I'd like to do is change the 'range', 'columns', 'selection' to be a generic variety to be used in any cell/range/selection

macro should format cell directly to the left, then fill down
can anyone help me with the code? many thanks


Sub AS400_Date_Format()
'
' AS400_Date_Format Macro
' Format 8 digit AS400 date
'
' Keyboard Shortcut: Ctrl+Shift+D
'
Selection.NumberFormat = "m/d/yyyy"
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]=99999999,DATE(2222,2,2),DATE(LEFT(RC[-1],4),MID(RC[-1],5,2),RIGHT(RC[-1],2)))"
Range("BA2").Select
Columns("BA:BA").ColumnWidth = 9.43
Selection.AutoFill Destination:=Range("BA2:BA3940")
Range("BA2:BA3940").Select
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How would you determine what the range was to apply this to?

Would it be based on the current selection?

By the way, have you tried other methods to convert the dates to 'real' dates?
 
Upvote 0
ideally, i'd just like to change 1 cell and then fill down. I can create a function to do this, but would prefer if a macro could complete the multiple steps.

range and columns will change depending on data
 
Upvote 0
I don't quite follow, you want to trigger the code by changing a cell?

What cell would that be and what change would be made?

Are you trying to convert some imported data so the dates are recognised as such by Excel?
 
Upvote 0
yes, trying to convert imported data

Bad date can appear in any column depending on the query.
Good date (macro date) would be in Row 2, Column +1

Range can be any length depending on the query.
I'd like to fill down rather than fill range but not sure if this is possible. I figured Fill down should detect the appropriate range
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

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