Getting Type Mistmatch error when using .Numberformat

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Hello

I am Getting Type Mistmatch error when using .Numberformat marked in Red
Did I miss something here therefore am i getting Type Mismatch error or is it the wrong method that i've adopted
Code:
Public Sub nmbrFormat()

Dim rNos As Range, cellsRNos As Range
Dim wsMis As Worksheet
Set wsMis = Worksheets("Sheet4")

With wsMis
   Set rNos = Union(.Columns("BF"), .Columns("BG"), .Columns("BH"), .Columns("BI"), _
   .Columns("BK"), .Columns("BL"), .Columns("BM"), .Columns("BN"), .Columns("BP"), .Columns("BQ"), _
   .Columns("CG"), .Columns("CH"), .Columns("CI"), .Columns("CJ"))
End With

For Each cellsRNos In rNos
[COLOR=#ff0000]   cellsRNos.NumberFormat = Trim(Replace(Format(String(Len(Int(cellsRNos.value)) - 1, "#"), " @@\\,@@\\,@@\\,@@\\,@@\\,@@\\,@@0"), " \,", "")) & ".00"[/COLOR]
Next
NimishK
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What do you actually have in the cells you are looping through?
 
Upvote 0
What do you actually have in the cells you are looping through?
But Natural the numeric values in other words (Amount).
Are you trying to indicate the error i am facing is it because of Blank Cells in the columns

rNos is set to range of columns
and cellsRnos is again set to cells of amount of rNos
 
Last edited:
Upvote 0
Can you post some examples of the values?
 
Upvote 0
in col CI
458,660
1108,000
94,400
146,320

<tbody>
</tbody>

Also the values are displayed as Formula

CI263=-(BF263-BK263-BP263)
 
Last edited:
Upvote 0
When you get the error what is the value of cellsRNos?
 
Upvote 0
I am not quite sure is it because of Header Row which contains text and that is why Error

When you get the error what is the value of cellsRNos?
How can i check the above ?
 
Upvote 0
If there is a header row then it's going to be included in your loop because you are using entire columns.

To skip the header row you could try something like this, which is based on the header row being in row 1.
Code:
For Each cellsRNos In rNos
    If cellsRNos.Row > 1 Then
        cellsRNos.NumberFormat = Trim(Replace(Format(String(Len(Int(cellsRNos.value)) - 1, "#"), " @@\\,@@\\,@@\\,@@\\,@@\\,@@\\,@@0"), " \,", "")) & ".00"
    End If
Next
 
Last edited:
Upvote 0
Thanks yes it worked except in between there was error 2015 which again checked on sheet as there was blank cell which turned to give formula error. Now Rectified
Thank you so much
 
Upvote 0

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top