Cell Formatting Issue

H

Henry Jones

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
 
G

Guest

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.
 
H

Henry Jones

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
 
H

Henry Jones

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.
 
B

Bob Phillips

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

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 
H

Henry Jones

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
 

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