Formatting a cell to % or General based on the data in other cell

SJC27x5

New Member
Joined
Apr 6, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have drop down box where I need to select certain paraments.

Marks
% to Total marks

Ex: the result will fetch in cell B10, I need make the cell formatting of B10 to % if the selection in dropdown is % to Total marks, and the formatting of B10 to General for selection as marks.

I was searching for this in google, but didn't find an answer.

Thanks for your support.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,912
Office Version
  1. 365
Platform
  1. Windows
So you want to format cell B10 based on the selection of a drop-down box?

Assuming that:
- the drop-down box is a Data Validation box
- the drop-down box is in cell A1

Then right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window that pops up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Change address to cell of drop-down box
    If Target.Address = Range("A1").Address Then
        Select Case Target.Value
            Case "Marks"
                Range("B10").NumberFormat = "General"
            Case "% to Total marks"
                Range("B10").NumberFormat = "0.00%"
        End Select
    End If

End Sub
This will automatically run when the drop-down box value is changed.

Simply change the "A1" address in the code to match whatever range the drop-down box is located in.
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,441
Messages
5,636,305
Members
416,912
Latest member
danluk12

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
Top