Ideas for adding text to a cell based on criteria.

jusbgrub

New Member
Joined
Feb 16, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Column A has a pull-down menu with each cell that has various "Zones" to choose from. Column C has cells where numbers are entered. If for example, "Zone 1" is selected in A:2, is there a way to add the letters "TP" or "CD" to the beginning of the number in C:2 after it is typed based on what selection has been chosen in A:2?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Welcome to the Board!

I think that will probably require VBA. Are you good with that?
If so, what exactly are your rules (what is your complete listing of values in your drop-down menu, and what prefix is associated with each)?

If you are unable to use VBA, you could use a "helper" column, i.e. enter the number in column C, and have a formula in column D that shows this number with its appropriate prefix.
 
Upvote 0
add the letters "TP" or "CD"
You have to decide which of the two you want to add.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a number in column C and press the ENTER key.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 3 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Target.Offset(, -2) = "Zone 1" Then
        Target = "TP" & Target
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
If you are unable to use VBA, and presuming that your "pull-down menu" is a form control box. As Joe4 has said above, you can use a helper column to process the additional letter as show below.


Screenshot 2023-02-16 at 16.49.54.png


Cell A1 contains the results of changing the values in the form control box. If you have a version newer than Excel 2019, you can use IFS to shorten the formula.

Excel Issue2.xlsx
ABCDEF
14DATA ENTRY BOXNEW VALUELIST OF ZONESLETTER TO ADD
23333BB3333Zone 1TP
34444BB4444Zone 2CD
45555BB5555Zone 3AA
5Zone 4BB
Sheet1
Cell Formulas
RangeFormula
D2:D4D2=IF($A$1=1,$F$2&C2,IF($A$1=2,$F$3&C2,IF($A$1=3,$F$4&C2,IF($A$1=4,$F$5&C2,""))))
 
Upvote 0
Thanks for the response. Im "OK" with VBA. I made a sample sheet and uploaded a picture. I am just stumped on how to keep excel from just adding the prefix and wiping out the number.
 

Attachments

  • sample.PNG
    sample.PNG
    29.6 KB · Views: 2
Upvote 0
Did you try the macro I suggested in Post #3?
 
Upvote 0
I did. It didn't work. The cells i gave are not representative of my actual sheet. I also need Zones 1 and 2 to be "CD" and Zones 3 and 4 to be "TP". On my actual sheet the pull downs are in E3:E30 and the numbers i need the prefix added to is G3:G30. This is a daily sheet and is cleared every day and filled out from top to bottom, left to right.
 
Upvote 0
I got this to work. Thank you very much for your help.



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 5 Then Exit Sub
If Target.Column <> 7 Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
If Target.Offset(, -2) = "Cassioli" Then
Target = "CD" & Target
End If
If Target.Offset(, -2) = "Doorline" Then
Target = "CD" & Target
End If
If Target.Offset(, -2) = "Testing" Then
Target = "TP" & Target
End If
If Target.Offset(, -2) = "Packout" Then
Target = "TP" & Target
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

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