Changing cell formatting programatically

H

Harry

Hi.. is there a way to change the formatting of a cell range (ie
a2:d2) .

Example, I want to change the formatting from "General" to "Date
(such as 03/14/01) or from date to "General"

I am wondering if there is a way to do this through code rather than
right clicking on the cell, and going through "Format Cells"

thanks,
Harry
 
D

Dave Peterson

This is an excellent opportunity to record a macro to see what it does for you:

I got this:
Option Explicit
Sub Macro1()
Range("A2:D2").Select
Selection.NumberFormat = "m/d/yy"
End Sub

But you can see that excel recorded your actions. You may want to adjust it
slightly to remove the .select and selection stuff.

Option Explicit
Sub Macro2()
Range("A2:D2").NumberFormat = "m/d/yy"
End Sub

I'll leave it to you for the "General" format change.

I'm guessing that you're new to macros. You may want to read David McRitchie's
notes:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
H

Harry

I've been programming Excel for about a year.. off and on. Still, no
time like the present to learn basic things.

I have an O'Reilly book on Excel Macros and couldn't find what I was
looking for,, still I appreciate the tip.

Regards
Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top