Format cell as Currency or Number based on value of another cell

CDP

New Member
Joined
Aug 17, 2010
Messages
1
How can I format a cell to be either currency or a number, based on another cell value? For example, if A1="BP", then B1 should auto format as a Number when a value is entered. However, if A1="Flat fee", then B1 should auto format to be Currency when a value is entered. Cell A1 (whole column actually) is a drop-down list with only these 2 possible options. Is this possible to make B1 auto format based on the value of A1? Thanks!!!
 
Right-click on the sheet tab that you want this to work on and select "View Code" from the pop-up menu. Paste the code below in the VBA edit window.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cel As Range
    
    If Not Intersect(Target, Columns("A:A")) Is Nothing Then
    
        For Each cel In Intersect(Target, Columns("A:A"))
        
            If cel.Value = "Flat fee" Then
                cel.Offset(0, 1).NumberFormat = "$#,##0.00"
            Else
                cel.Offset(0, 1).NumberFormat = "General"
            End If
                
        Next cel
    End If
End Sub
 
Upvote 0

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