Change Test of Cell based on Value in VBA

Jones1413

New Member
Joined
Jul 26, 2019
Messages
25
Hello,

I need to write a VBA macro that will change the text of a cell based on the value already in the cell. For example, the cell can be anywhere in Column A and if the cell value equals "Jones1413" I want to change the text of that cell to "BJones". The rows of data can change and the value will not be in the same cell every time the report is ran.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,916
Office Version
  1. 365
Platform
  1. Windows
I think we need some more details, such as:
1. Where is the "key" that tells us what we are looking for, and what we want to change it to?
2. How is this VBA code to be run? Are you going to do it manually, or do you want it to happen automatically?
If automatically, what "action" should trigger the code to run?
 

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
392
Office Version
  1. 2016
Platform
  1. Windows
This example describes simple find word and replace...
VBA Code:
Private Sub ReplaceWord()

    Dim vInput1 As String, vInput2 As String, vNR As Long, vF As Range
    
    vInput1 = InputBox("Input word to find")
    vInput2 = InputBox("Replace word with...")
    vNR = Cells(Rows.Count, "A").End(xlUp).Row
    Set vF = Range("A1:A" & vNR).Find(vInput1)
    If Not vF Is Nothing Then
        Range("A" & vF.Row) = vInput2
    End If
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,505
Messages
5,636,717
Members
416,936
Latest member
Saurabh786

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