Include contents of cell in custom number format

urungus

New Member
Joined
Mar 4, 2009
Messages
4
Is it possible to include the contents of cell A1 in a custom number format? Suppose cell A1 contains string "USD" representing currency. Cell B1 is to have custom number format, if user types 100 in cell B1, it should be displayed as "100 USD". Then if cell A1 is changed to "GBP", cell B1 should update to show "100 GBP". Is this possible?
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
It might be possible with conditional formatting, but then you need to define a rule and a format for each currency.

So my suggestion would be to use VBA, like
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim i As Long
    
    Set rng = Intersect(Target, Columns(2))
    If rng Is Nothing Then Exit Sub
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    On Error Resume Next
    
    For i = 1 To rng.Count
        rng(i).NumberFormat = "#,##0.00 """ & rng(i).Offset(0, -1) & """"
    Next i
    
    On Error GoTo 0
    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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