Is there a way to get two different number formats for same cell?

aedctalk

Board Regular
Joined
Oct 9, 2010
Messages
156
I ask because i'm pulling two different sets of data into the same cells.

I have a dropdown that has two sheet names in M120

then i reference it in the cell below using

=IF(ISERR(INDIRECT($M$120&"!AE149")),,INDIRECT($M$120&"!AE149"))

Thus i'm pulling attendance from one sheet that i just want 6,100 format
and percapita from another sheet that i want two decimals 3.50 both appear in same cell lets say A1 .. depending upon whats selected in M120


Is there any way to change the format depending on what value is in M120 .. or by any other method?

Thanks so much :P
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Have you taken a look at the TEXT() function?

(I removed the iserr() bit from below to make the formula a little more obvious, plus if the values from a dropdown you shouldn't need to worry too much about a bad value)

Code:
=IF($M120 = "Sheet3",TEXT(INDIRECT($M$120&"!AE149"),"#,###"),TEXT(INDIRECT($M$120&"!AE149"),"#.00"))
 
Upvote 0
If you are using 2007 or later then you can apply number formats in conditional formatting, so you can base them on the values of a different cell to the one you are formatting.
 
Upvote 0
Putting this in the sheet's code module is a general solution.
Code:
Private Sub Worksheet_Calculate()
    On Error Goto ErrorOut

    With Sheet1.Range("M120")
    
        Select Case LCase(CStr(.Value))
            Case "decimal"
                .Dependents.NumberFormat = "0.00"
            Case "thousand"
                .Dependents.NumberFormat = "#,##0"
            Case Else
                .Dependents.NumberFormat = "general"
        End Select
        
    End With

ErrorOut:
On Error Goto 0
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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