Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2478
  • Last Modified:

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!
0
btkrausen
Asked:
btkrausen
  • 2
1 Solution
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now