vba to replace value with a value from another sheet based on criteria

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have this VBA that imports a workbook("Sheet1"), instead of replacing the values each time I am trying to have a VBA to do it for me. The values change every so often, so it needs to be as universal as possible. I have no idea where to start for this.
The correct values are in sheet ("Data Validation") Columns E1, F1, G1.
The names of the personnel will be under each of those columns in the "Data Validation" sheet.
If the names (column "B6 and below") on sheet1 are equal to one of those names in the "Data Validation" sheet it will replace the value currently in "Sheet1" column I with the value in the same column as the name, but the first row.
Example is below

Sheet1
Billy, Boba
Go, Pror
Gordib, Niunb
Hunker, Naag
Pop, Babu

Changes to that
|
|
\|/

Sheet1
Billy, BobPizza
Go, ProRolls
Gordib, NiunSpaghetti
Hunker, NaaSpaghetti
Pop, BabDonuts


Based on that
|
|
\|/



Data Validation sheet
columnECoulmnFCoulumn G
PizzaSpaghettiDonuts
Billy, BobGordib, niunPop, Bab
Hunker, Naa
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about:

VBA Code:
Sub ReplaceValue()
  Dim i As Long, f As Range
  With Sheets("Sheet1")
    For i = 6 To .Range("B" & Rows.Count).End(3).Row
      Set f = Sheets("Data Validation").Range("E:G").Find(.Range("B" & i), , xlValues, xlWhole)
      If Not f Is Nothing Then .Range("I" & i).Value = Sheets("Data Validation").Cells(1, f.Column)
    Next
  End With
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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