VBA code to find multiple different strings in a column and replace them with a new value

rkol297

Board Regular
Joined
Nov 12, 2010
Messages
131
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello I need VBA code that will lookin column D and for values:A, B, C, D, E, F, G rename all instances of these as Xthen in the same column forH,I,J,K rename all instaces of these as Zthen in the same column for valuesL, M, N, O, P, Q rename all instances as YI have a case code below that I like as I can add new values to it as in the future I may need to add values or remove current ones is there a way to do the above mentioned in this type of a code or is there a better way of doing it?Keep in mind the code below isnt being used to replace the values its just to illustrate that I like this code and the way its setup.
Code:
   Sheets("RPH DAILY PRODUCTIVITY").Select    Dim CelREMOVENONPAHIG As Range, RngREMOVENONPAHIG As Range, iREMOVENONPAHIG As Long    Set RngREMOVENONPAHIG = Columns("D").SpecialCells(xlConstants, xlTextValues)    For iREMOVENONPAHIG = RngREMOVENONPAHIG.Count To 2 Step -1        Select Case Range("D" & iREMOVENONPAHIG).Value            Case "ACTP", "ADCC", "ADCR", "ALDZ", "ARAL", "BERT", "EPAC", "EPAP", "EPOP", "ELAP", "FL50", "F100", "FABF", "FABZ", "FLBO", "FPAP", "FZYR", "GAMC", "GAMS", "GGIV", "GGSC", "GKIV", "GKSC", "GLSA", "GMPX", "HIZA", "IVGB", "IVGF", "IVGP", "IVGS", "LETA", "LUMZ", "MYOZ", "NGLF", "NGLZ", "REMO", "REMP", "REVA", "REVC", "RMIP", " RMIV", "SILD", "TPAP", "TRAB", "TRAC", "TYVA", "TYVP", "TYVS", "VENP", "VENT", "VPRV", "ZEMA", "ZYME", "ZYMF"                'do nothing            Case Else                Rows(iREMOVENONPAHIG).Delete            End Select    Next iREMOVENONPAHIG
 

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
see if this is what you need

Code:
Sub check_letters()
  Dim i As Long, LR As Long
  
  LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
  Sheets("RPH DAILY PRODUCTIVITY").Select ' change this to your file name
  
  For i = 2 To LR
    Select Case Range("D" & i).Value
    Case "A", "B", "C", "D", "E", "F", "G"
        Cells(i, "D") = "XThen"
    Case "I", "J", "K"
        Cells(i, "D") = "ZThen"
    Case "M", "N", "O", "P", "Q"
        Cells(i, "D") = "YI"
    End Select
  
  Next i
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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