Excel Macro to Change Column Format to Number?

I'm having a terrible time with what I think should be a very simple macro.  I need to select columns E and F and change their format to Number.

Here is what I have currently:
Sub EF_to_Number()
'
' EF_to_Number Macro
'
'
    Range("E:E,F:F").Select
    Selection.NumberFormat = "0.00"
End Sub

Open in new window

When you run this macro it changes ALL columns to number format - not just E and F.

I've also tried selecting just one column or the other and the same problem occurs.  What am I missing?

For what it's worth, I'm using Excel 2013.

Thanks!
btkrausenAsked:
Who is Participating?
 
Glenn RayExcel VBA DeveloperCommented:
Try this revision to your code:
 
Sub EF_to_Number()
'
' EF_to_Number Macro
'
'
    Columns("E:F").NumberFormat = "0.00"
End Sub

Open in new window



Regards,
-Glenn
0
 
MontoyaProcess Improvement MgrCommented:
Since you're only doing two columns:

Worksheets("Sheet1").Columns(5).NumberFormat = "0.00"  // Where 5 is the alphabet position of the column
Worksheets("Sheet1").Columns(6).NumberFormat = "0.00"

That would do column e and f
0
 
MontoyaProcess Improvement MgrCommented:
I didnt type fast enough.. ;)
0
 
btkrausenAuthor Commented:
That worked perfectly!  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.