Trouble with changing cell numberformat with VBA

jmwbowen

Board Regular
Joined
Jul 27, 2012
Messages
58
Hi,

I believe Range.Numbeformat is the property I am looking for.

I have a cell with a dropdown picker. If the user chooses "Distractor" from the picker, Worksheet_Change triggers an Inputbox to open, asking what kind of distractor it is. We'll use "Gloves" for this example.

I want the cell to display "Distractor - Gloves" while keeping the actual value as "Distractor"

The following is not working for me:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim DistractorText As String
Select Case Target.Address
Case "$B$23"
    If Target.Value = "Distractor" Then
        DistractorText = InputBox("Type of Distractor:")
        Target.NumberFormat = "@" & " - " & DistractorText

FYI: There's more code, but I copy-pasted the trouble area. The last line using the NumberFormat property is giving me trouble.

Help?
 

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).
Try:
Code:
Target.NumberFormat = "@"" - " & DistractorText & """"
 
Upvote 0
Thank you moderator, that did it!

On a separate note, is there a way to mark a thread as "solved"? I'm new here.
 
Upvote 0
No, we don't use that. A simple 'thank you' at the end is enough of an indicator. :)

Welcome aboard, but the way.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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