Marcro for looking for certain number and change it to certain word.

shawrod

Active Member
Joined
Oct 1, 2010
Messages
399
I am looking for a macro that would look into column A and if it finds 5, change it to apple. If it finds 6, change it to orange. If it finds 9, change it to plum. If it finds 12 change it banana. Can anyone help?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sub macro1()
Dim i As Integer
i = 1
Do
If Cells(i, 1).Value = 5 Then
Cells(i, 1).Value = "apple"

ElseIf Cells(i, 1).Value = 6 Then
Cells(i, 1).Value = "orange"

ElseIf Cells(i, 1).Value = 9 Then
Cells(i, 1).Value = "plum"
ElseIf Cells(i, 1).Value = 12 Then
Cells(i, 1).Value = "banana"
End If
i = i + 1


Loop While Cells(i, 1).Value <> ""
End Sub
 
Upvote 0
Sub macro1()
Dim i As Integer
i = 1
Do
If Cells(i, 1).Value = 5 Then
Cells(i, 1).Value = "apple"

ElseIf Cells(i, 1).Value = 6 Then
Cells(i, 1).Value = "orange"

ElseIf Cells(i, 1).Value = 9 Then
Cells(i, 1).Value = "plum"
ElseIf Cells(i, 1).Value = 12 Then
Cells(i, 1).Value = "banana"
End If
i = i + 1


Loop While Cells(i, 1).Value <> ""
End Sub

That did it! Thank you so much!
 
Upvote 0
Here's my attempt:

Code:
Option Explicit
Sub Macro2()

    'Written by Trebor76
    'Visit my website
    
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngCell In Range("A1", Range("A" & Rows.Count).End(xlUp)) 'Starts at row 1. Change to suit.
        Select Case rngCell.Value
            Case Is = 5
                rngCell = "apple"
            Case Is = 6
                rngCell = "orange"
            Case Is = 9
                rngCell = "plum"
            Case Is = 12
                rngCell = "banana"
        End Select
    Next rngCell
    
    Application.ScreenUpdating = True
    
    MsgBox "Process is complete"
    
End Sub

HTH

Robert
 
Upvote 0
Here's my attempt:

Code:
Option Explicit
Sub Macro2()

    'Written by Trebor76
    'Visit my website
    
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngCell In Range("A1", Range("A" & Rows.Count).End(xlUp)) 'Starts at row 1. Change to suit.
        Select Case rngCell.Value
            Case Is = 5
                rngCell = "apple"
            Case Is = 6
                rngCell = "orange"
            Case Is = 9
                rngCell = "plum"
            Case Is = 12
                rngCell = "banana"
        End Select
    Next rngCell
    
    Application.ScreenUpdating = True
    
    MsgBox "Process is complete"
    
End Sub

HTH

Robert

Thanks, Robert. I like this one too!
 
Upvote 0

Forum statistics

Threads
1,202,991
Messages
6,052,965
Members
444,622
Latest member
Kriszilla

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