Create a macro to format a column

Solved/Closed
Vivian - Aug 5, 2010 at 12:32 PM
 Vivian - Aug 20, 2010 at 08:17 AM
Greetings,

I am not a programmer but I know how to create basic macros that would perform simple repeated tasks in a fixed range within a sheet.

Right now I'm encountering a task that would require a tiny bit of programming versus a simple recording of a macro. I happen to find this site . . . I was wondering if someone could help. I am greatful for those who could take their time to resolve this. Many thanks in advance.

Routinely I recieve Excel workbooks from new vendors. Each vendor would have their fields(columns) and formats arranged differently. I'm wondering if some could show me how to create a macro that would format a column that I select.

For example, when I open up a workbook, if I select column C (a date field) and run the macro, the macro would format column C into mm/dd/yy. If I select Column F and run the macro, the macro would format coumn F into mm/dd/yy.

Again - many thanks.

2 replies

Place this on a module on VBA Editor

Sub format()
Selection.NumberFormat = "mm-dd-yy"

End Sub

When you want to run the macro, select the column you want to format and then run the macro
1
Hi Bren,

Thank you so much. This is exactly what I'm looking for. I know I could do it menually by clicking the menu bar or do the "text to column" as suggested by rizvisa1. But when there are so many date columns to be formatted in a workbook, the manual task becomes very tedeous. You are a life saver. Thank you again!
0
rizvisa1
Posts
4479
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
769
Aug 5, 2010 at 12:49 PM
If only thing that you want to do is covert the text of columns into date, then you can use the Text to column option available under Data
0