View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Formatting numbers

moExcelWS.Cells.(3,3)NumberFormat="[<=9999999]###-####;(###) ###-####"

First off, I assume the missing "dot" that should be in front of
"NumberFormat" is a typo. What is moExcelWS... a variable containing the
worksheet name or a variable containing a reference to the worksheet? If the
former, you would need to make it an argument to the Worksheet object
call...

Worksheets(moExcelWS).Cells(3,3).NumberFormat=.... etc

I wonder, if there is way to "preformat" the whole column, so when the
numbers are entered into it they will be automatically formatted as the
phone numbers?


Do you mean in code (as opposed to selecting the column and using
Cell/Format on the worksheet directly)? If so, you should be able to do
something like this in code...

Columns("G").NumberFormat = "[<=9999999]###-####;(###) ###-####"

Where you would change the column reference to suit your needs and preface
it with a worksheet reference.

--
Rick (MVP - Excel)


"fred" wrote in message
...
Thank you, Rick
When I try this:
moExcelWS.Cells.(3,3)NumberFormat="[<=9999999]###-####;(###) ###-####"
there is a compile error:
"Expected: identifier or bracketed expression"

I wonder, if there is way to "preformat" the whole column, so when the
numbers are entered into it they will be automatically formatted as the
phone numbers?
Thanks,
Fred

"Rick Rothstein" wrote in message
...
Not sure how you want to implement this, but the following should give
you an idea how to proceed...

Selection.NumberFormat = "[<=9999999]###-####;(###) ###-####"

--
Rick (MVP - Excel)


"fred" wrote in message
...
Hello,
When using Excel automation, how to programmatically format all
numbers in the specified column as the phone numbers.
I can see it in the Excel menu there is possible to do
FormatSpecialPhone Numbers.
How to do that programmatically?
Thanks,
Fred