Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Cell Formatting Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Henry Jones - 25 Jan 2007 15:40 GMT
On my worksheet (Excel 2003), I am using the following code to format:

  Range("D6:D555").Select
  Selection.NumberFormat = "0.0000"

The problem is every 40 or so cells I have merged 5 rows from A to S.  These
are title rows to be printed and the text is centered.  It seems that each
cell on the page has been formatted to 0.0000

How can I just format the range D6:D555 without formatting the other cells?

Thanks in advance
galimi - 25 Jan 2007 15:59 GMT
Henry,

I would change the code to something like this

set rng=Range("D6:D555").Select

for each cl in rng
    if not rng.mergecells then
         Selection.NumberFormat = "0.0000"
    end if
next

This will skip the mergecell selections.  You can expand on this code to
determine if the cell selected within the merge cell is NOT your heading and
then format that appropriately.
Signature

http://HelpExcel.com
ed@helpExcel.com

> On my worksheet (Excel 2003), I am using the following code to format:
>
[quoted text clipped - 8 lines]
>
> Thanks in advance
Henry Jones - 25 Jan 2007 16:12 GMT
Thanks for replying and I just tried your code and received a Type Mismatch
on the following line:

set rng=Range("D6:D555").Select

Any ideas?

Thanks,

Henry

> Henry,
>
[quoted text clipped - 28 lines]
>>
>> Thanks in advance
Henry Jones - 25 Jan 2007 16:18 GMT
After looking at your helpexcel.com page I found some code and adjusted mine

Dim rng As Range
Dim cl As Range

 Set rng = Sheet1.Range("D6:D555")

For Each cl In rng
    If Not rng.MergeCells Then
         Selection.NumberFormat = "0.00"
    End If
Next

I changed the format to 0.00 to test, the range didn't change and cells A-I
are selected.

I don't know what to do now.

> Thanks for replying and I just tried your code and received a Type
> Mismatch on the following line:
[quoted text clipped - 39 lines]
>>>
>>> Thanks in advance
galimi - 25 Jan 2007 16:26 GMT
Instead of selection.numberformat, it should be cl.numberformat

Signature

http://HelpExcel.com
ed@helpExcel.com

> After looking at your helpexcel.com page I found some code and adjusted mine
>
[quoted text clipped - 57 lines]
> >>>
> >>> Thanks in advance
Henry Jones - 25 Jan 2007 16:30 GMT
I fixed it and now it works.  Thanks very much.

Henry

> Instead of selection.numberformat, it should be cl.numberformat
>
[quoted text clipped - 64 lines]
>> >>>
>> >>> Thanks in advance
galimi - 25 Jan 2007 16:19 GMT
Henry,

My apologies.  

set rng=Range("D6:D555")

The select method should not be there.

Signature

http://HelpExcel.com
ed@helpExcel.com

> Thanks for replying and I just tried your code and received a Type Mismatch
> on the following line:
[quoted text clipped - 39 lines]
> >>
> >> Thanks in advance
Bob Phillips - 25 Jan 2007 16:19 GMT
Few bugs in the code

Set rng = Range("D6:D555")

For Each cl In rng
    If Not cl.MergeCells Then
         cl.NumberFormat = "0.0000"
    End If
Next

Signature

---
HTH

Bob

(change the xxxx to gmail if mailing direct)

> Thanks for replying and I just tried your code and received a Type
> Mismatch on the following line:
[quoted text clipped - 39 lines]
>>>
>>> Thanks in advance
Henry Jones - 25 Jan 2007 16:25 GMT
Thanks, I caught and changed the rng.NumberFormat to cl.Numberformat, here
is my adjusted code,

Dim rng As Range
Dim cl As Range

 Set rng = Sheet1.Range("D6:D555")

For Each cl In rng
    If Not cl.MergeCells Then
         Selection.NumberFormat = "0.00"
    End If
Next

but the range doesn't change to 2 decimal places....  What is wrong?

Thanks,

H

> Few bugs in the code
>
[quoted text clipped - 49 lines]
>>>>
>>>> Thanks in advance
Henry Jones - 25 Jan 2007 16:33 GMT
Hi Bob,

I didn't see the cl.numberformat you had changed.  It works now,

Thank you
> Thanks, I caught and changed the rng.NumberFormat to cl.Numberformat, here
> is my adjusted code,
[quoted text clipped - 70 lines]
>>>>>
>>>>> Thanks in advance
galimi - 25 Jan 2007 16:42 GMT
Henry,

I have copied an example to http://www.HelpExcel.com/examples

The name is decimal.xls

Signature

http://HelpExcel.com
ed@helpExcel.com

> Thanks, I caught and changed the rng.NumberFormat to cl.Numberformat, here
> is my adjusted code,
[quoted text clipped - 69 lines]
> >>>>
> >>>> Thanks in advance
Henry Jones - 25 Jan 2007 16:51 GMT
Thanks for the code sample.  I did get it working and I appreciate your help
> Henry,
>
[quoted text clipped - 81 lines]
>> >>>>
>> >>>> Thanks in advance
galimi - 25 Jan 2007 16:42 GMT
You need to change selection.numberformat to cl.numberformat
Signature

http://HelpExcel.com
ed@helpExcel.com

> Thanks, I caught and changed the rng.NumberFormat to cl.Numberformat, here
> is my adjusted code,
[quoted text clipped - 69 lines]
> >>>>
> >>>> Thanks in advance
galimi - 25 Jan 2007 16:32 GMT
Thanks Bob.
Signature

http://HelpExcel.com
ed@helpExcel.com

> Few bugs in the code
>
[quoted text clipped - 49 lines]
> >>>
> >>> Thanks in advance
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.