TimFred
asked on
Simple macro writing to format MS Excel fields
I am new to macro writing and need some help. I need to write a simple VB macro for MS Excel that will format two columns:
One column I need to add a 0 before the number. So that when the user enters 7 in the Excel column the macro will format that column by adding a 0 in front of it. The result will be a 07 in the field.
The other column I need to have the macro convert a month and day date to this fomat MM/DD.
Some basic macro code I have is:
Range("I1").Select
ActiveCell.FormulaR1C1 = "X"
Range("I2").Select
ActiveWorkbook.Save
but I need to format the cells. how do I do this?
One column I need to add a 0 before the number. So that when the user enters 7 in the Excel column the macro will format that column by adding a 0 in front of it. The result will be a 07 in the field.
The other column I need to have the macro convert a month and day date to this fomat MM/DD.
Some basic macro code I have is:
Range("I1").Select
ActiveCell.FormulaR1C1 = "X"
Range("I2").Select
ActiveWorkbook.Save
but I need to format the cells. how do I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why don't you use the Formatting that is already there for dates and Numbers, from the Format Cells|Numbers tab?
If you select Custom then in the Type, before General, type "0", so you have "0"General
You can set the date format from there as well
Bill