Create a macro to format a column [Solved/Closed]

Report
-
 Vivian -
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
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

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!
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
761
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

Newsletter

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!