Put a number on a cell and it showing word/words

Tracyng2406

New Member
Joined
Feb 26, 2018
Messages
9
Hi All,

Could anyone teach me how to put a number (e.g. 1) in a cell, after enter it will show a word (e.g. apple / sweet apple) ?

thanks a lot.
 
You said in post 1
Could anyone teach me how to put a number (e.g. 1) in a cell, after enter it will show a word (e.g. apple / sweet apple) ?
1. Put 1 in what cell?
2. If 1 equals "Apple" what does 2 equal?
3. Will it always be the same cell?

Where is the list of values like "Apple" "Pear"
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
although it's complicated, I've tried and save. it needs to debug, I've no idea where is the error
 
Last edited:
Upvote 0
30k3i29.png
 
Upvote 0
Sorry we were not able to help you.
But when you say I want to put a 1 in a cell and have "Apple" put into same cell we need more information.
 
Upvote 0
I will give up.
I don't think that you should do that just yet. :)

See if you can get this to do what you want, or close to it. It again involves vba code, but has a simpler implementation than the previous suggestion.
Try these steps in a new test workbook:

1. Set up a sheet exactly like you have shown in post #5 , except for the values in B9:D21
2. Right click the sheet name tab and choose "View Code".
3. Copy and Paste the code below into the main right hand pane that opens at step 1.
4. Close the Visual Basic window & test by entering values into the B9:D21 range.
5. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range, Found As Range, SearchRows As Range
  
  Const EntryHeaderRow As Long = 8  '<- Edit if required
  
  Set Changed = Intersect(Target, Rows(EntryHeaderRow + 1 & ":" & Rows.Count))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    Set SearchRows = Rows("1:" & EntryHeaderRow - 1)
    For Each c In Changed
      If Len(c.Text) > 0 Then
        Set Found = Nothing
        Set Found = SearchRows.Find(What:=c.Text, LookAt:=xlWhole, MatchCase:=True)
        If Not Found Is Nothing Then c.Value = Found.Offset(, 1).Value
      End If
    Next c
    Application.EnableEvents = True
  End If
End Sub

Here is what my sheet looks like after following the above steps and at step 4 I have entered a "2" into cell B9, a "D" into C13 and "II" into D11.


Book1
ABCDEFGH
11AppleARedIOpen
22OrangeBBlueIIClose
3CPurple
4DYellow
5EGreen
6
7
8NameFruitColourStatus
9JohnOrange
10Ann
11TomClose
12Susan
13RobertYellow
14Jade
15Sue
16Helen
17Jeffery
18Joey
19Dicky
20Suki
21Jimmy
Sheet1



If you get any errors like before, again tell us what they say (like in post #13 ) but also click the 'Debug' button on that message box and tell us what line of the code gets highlighted.

If the code works, then it may be that we still have to make some amendments if your real sheet is not set out exactly like this sample, but we will have "proof of concept".
 
Upvote 0
Hi Peter,

Million thanks for your instructions. I've followed and it's work. It can help me a lot on my project!!

thanks!!!
 
Upvote 0
Good Day May This will help You
But I'm Sorry about change Strings to numbers such as A to 1, B to 2 ...D to 4 ,E to 5 and I to 1 & II to 2 , maybe Format Conditions not work with Text if you can help Me

Note: Cells still have Numbers Value and Display Text

Code:
Sub AddFormatCondition()
    
    
Dim Rng As Range, MyRange(1 To 3) As Range
Dim Appear(1 To 3) As Variant, Values(1 To 3) As Variant
Dim App(1 To 3) As Variant, Val(1 To 3) As Variant
Dim RngVal As String


Set MyRange(1) = Range("B9:B31")
Set MyRange(2) = Range("C9:C31")
Set MyRange(3) = Range("D9:D31")
Appear(1) = "Apple,Orange"
Appear(2) = "Red,Blue,Purple,Yellow,Green"
Appear(3) = "Open,Close"
Val(1) = "1,2"
'Val(2) = "A,B,C,D,E" ' FormatConditions not work with Text
Val(2) = "1,2,3,4,5" ' So convert to Numbers
'Val(3) = "I,II" ' FormatConditions not work with Text
Val(3) = "1,2" ' So convert to Numbers


Range("A1:A2") = Application.Transpose(Split("2,1", ","))
Range("A1:A2") = Application.Transpose(Split("Apple,Orange", ","))


Range("D1:D2") = Application.Transpose(Split("2,1", ","))
Range("E1:E2") = Application.Transpose(Split("Red,Blue,purple,Yellow,Green", ","))


Range("G1:G2") = Application.Transpose(Split("I,II", ","))
Range("H1:H2") = Application.Transpose(Split("Open,Close", ","))


Range("A9:A21") = Application.Transpose(Split("Jone,Ann,Tom,Susan,Rebert,Jade,Sue,Helen,Jeffery,Joey,Dicky,Suki,Jimmy", ","))


Range("B9:B21") = Application.Transpose(Split("2,1,1,2,2,2,1,1,1,2,2,1,2", ","))
'Range("C9:C21") = Application.Transpose(Split("B,A,A,C,C,E,E,A,C,D,C,C,A", ","))' FormatConditions not work with Text
Range("C9:C21") = Application.Transpose(Split("2,1,1,3,3,5,5,1,3,4,3,3,1", ",")) ' So convert to Numbers
'Range("D9:D21") = Application.Transpose(Split("I,II,I,I,I,II,I,I,I,II,II,II,I", ","))' FormatConditions not work with Text
Range("D9:D21") = Application.Transpose(Split("1,2,1,1,1,2,1,1,1,2,2,2,1", ",")) ' So convert to Numbers


    For I = 1 To 3
    For Each Rng In MyRange(I)
    With Rng
    
    .FormatConditions.Delete
    App(I) = Split(Appear(I), ",")
            For c = LBound(App(I)) To UBound(App(I))
            RngVal = Split(Val(I), ",")(c)
            If IsNumeric(RngVal) = True Then
            .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Rng.Address & "=" & RngVal & ""
            Else
            RngVal = """" & RngVal & """"
            .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Rng.Address & "=" & RngVal & ""
            End If
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            .FormatConditions(1).StopIfTrue = False
            .FormatConditions(1).NumberFormat = """" & App(I)(c) & """"
            Next
    End With
    Next
    Next
    
End Sub
 
Last edited:
Upvote 0
Good Day May This will help You
But I'm Sorry about change Strings to numbers such as A to 1, B to 2 ...D to 4 ,E to 5 and I to 1 & II to 2 , maybe Format Conditions not work with Text if you can help Me

Note: Cells still have Numbers Value and Display Text


Code:
Sub AddFormatCondition()
    
    
Dim Rng As Range, MyRange(1 To 3) As Range
Dim Appear(1 To 3) As Variant, Values(1 To 3) As Variant
Dim App(1 To 3) As Variant, Val(1 To 3) As Variant
Dim RngVal As String




Set MyRange(1) = Range("B9:B31")
Set MyRange(2) = Range("C9:C31")
Set MyRange(3) = Range("D9:D31")
Appear(1) = "Apple,Orange"
Appear(2) = "Red,Blue,Purple,Yellow,Green"
Appear(3) = "Open,Close"
Val(1) = "1,2"
'Val(2) = "A,B,C,D,E" ' FormatConditions not work with Text
Val(2) = "1,2,3,4,5" ' So convert to Numbers
'Val(3) = "I,II" ' FormatConditions not work with Text
Val(3) = "1,2" ' So convert to Numbers




Range("A1:A2") = Application.Transpose(Split("1,2", ","))
Range("B1:B2") = Application.Transpose(Split("Apple,Orange", ","))




Range("D1:D5") = Application.Transpose(Split("1,2,3,4,5", ","))
Range("E1:E5") = Application.Transpose(Split("Red,Blue,purple,Yellow,Green", ","))




Range("G1:G2") = Application.Transpose(Split("1,2", ","))
Range("H1:H2") = Application.Transpose(Split("Open,Close", ","))




Range("A9:A21") = Application.Transpose(Split("Jone,Ann,Tom,Susan,Rebert,Jade,Sue,Helen,Jeffery,Joey,Dicky,Suki,Jimmy", ","))




Range("B9:B21") = Application.Transpose(Split("2,1,1,2,2,2,1,1,1,2,2,1,2", ","))
'Range("C9:C21") = Application.Transpose(Split("B,A,A,C,C,E,E,A,C,D,C,C,A", ","))' FormatConditions not work with Text
Range("C9:C21") = Application.Transpose(Split("2,1,1,3,3,5,5,1,3,4,3,3,1", ",")) ' So convert to Numbers
'Range("D9:D21") = Application.Transpose(Split("I,II,I,I,I,II,I,I,I,II,II,II,I", ","))' FormatConditions not work with Text
Range("D9:D21") = Application.Transpose(Split("1,2,1,1,1,2,1,1,1,2,2,2,1", ",")) ' So convert to Numbers




    For I = 1 To 3
    For Each Rng In MyRange(I)
    With Rng
    
    .FormatConditions.Delete
    App(I) = Split(Appear(I), ",")
            For c = LBound(App(I)) To UBound(App(I))
            RngVal = Split(Val(I), ",")(c)
            If IsNumeric(RngVal) = True Then
            .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Rng.Address & "=" & RngVal & ""
            Else
            RngVal = """" & RngVal & """"
            .FormatConditions.Add Type:=xlExpression, Formula1:="=" & Rng.Address & "=" & RngVal & ""
            End If
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            .FormatConditions(1).StopIfTrue = False
            .FormatConditions(1).NumberFormat = """" & App(I)(c) & """"
            Next
    End With
    Next
    Next
    
Range("B9").Activate' see what contain


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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