VBA Code or formula to replace "Employee" with the second name of a different cell.

Vacheron23

New Member
Joined
Oct 11, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone, I have an annual assessment form that collects data from certain fields and based on the grading given to those fields, specific comments will be generated on column "AH" for each respective employee. All those comments state "Employee" at the beginning of each sentence. What I would like to do is to change the "Employee" with the second name from column B for each entry so that the comments will be more personalized. I had attached a photo of the file in question (unable to upload document). Any help is appreciated. Thank you very much!
 

Attachments

  • Sample.JPG
    Sample.JPG
    63.4 KB · Views: 9

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
you could use a formula to substitute the text:
Excel Formula:
=SUBSTITUTE(AH2,"Employee",TEXTAFTER(B2," "))
Then Value out the column and paste the values over the original text.
 
Upvote 0
Solution
In order to provide you with the right formula or code I'll need a little more information.

Where is your data (the text for column AH) stored?

Meanwhile here's a suggestion:

MrExcel_2024-11.xlsm
ABCD
1IDNameGradeComment
210000001DOE John0John is OK
310000002DOE Jane1Jane is a very good boi
410000003DOE Jean2Jean is a good boi
510000004DOE Jack3Jack is a bad boi
6
7Samples
8GradeComment
90is OK
101is a very good boi
112is a good boi
123is a bad boi
Sheet2
Cell Formulas
RangeFormula
D2:D5D2= TEXTAFTER(B2, " ", 1, 1, 0, "Employee") & " " & XLOOKUP(C2, $A$9:$A$12, $B$9:$B$12, 0,0,1)
 
Last edited:
Upvote 0
Hi Everyone, I have an annual assessment form that collects data from certain fields and based on the grading given to those fields, specific comments will be generated on column "AH" for each respective employee. All those comments state "Employee" at the beginning of each sentence. What I would like to do is to change the "Employee" with the second name from column B for each entry so that the comments will be more personalized. I had attached a photo of the file in question (unable to upload document). Any help is appreciated. Thank you very much!
Does this work for you?
  1. Select the cell(s) with formulas and press Ctrl + C to copy them.
  2. Select the same range.
  3. Press Excel's paste values shortcut: Ctrl + Alt + V, then V.
  4. Press Enter
Extract the word which carries the specific text.xlsm
ABAHAIAJ
1Full Name Comment
2Smith JohnEmployee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,John the quick brown fox jumps over the lazy dog, John the quick brown fox jumps over the lazy dog, John the quick brown fox jumps over the lazy dog,
3Jones HarryEmployee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,Harry the quick brown fox jumps over the lazy dog, Harry the quick brown fox jumps over the lazy dog, Harry the quick brown fox jumps over the lazy dog,
4Grayson Jane Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,Jane the quick brown fox jumps over the lazy dog, Jane the quick brown fox jumps over the lazy dog, Jane the quick brown fox jumps over the lazy dog,
Employee
Cell Formulas
RangeFormula
AJ2:AJ4AJ2=SUBSTITUTE(AH2,"Employee",INDEX(TEXTSPLIT(B2," "),2))
 
Upvote 0
Does this work for you?
  1. Select the cell(s) with formulas and press Ctrl + C to copy them.
  2. Select the same range.
  3. Press Excel's paste values shortcut: Ctrl + Alt + V, then V.
  4. Press Enter
Extract the word which carries the specific text.xlsm
ABAHAIAJ
1Full Name Comment
2Smith JohnEmployee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,John the quick brown fox jumps over the lazy dog, John the quick brown fox jumps over the lazy dog, John the quick brown fox jumps over the lazy dog,
3Jones HarryEmployee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,Harry the quick brown fox jumps over the lazy dog, Harry the quick brown fox jumps over the lazy dog, Harry the quick brown fox jumps over the lazy dog,
4Grayson Jane Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog, Employee the quick brown fox jumps over the lazy dog,Jane the quick brown fox jumps over the lazy dog, Jane the quick brown fox jumps over the lazy dog, Jane the quick brown fox jumps over the lazy dog,
Employee
Cell Formulas
RangeFormula
AJ2:AJ4AJ2=SUBSTITUTE(AH2,"Employee",INDEX(TEXTSPLIT(B2," "),2))
This is exactly what I need, thanks a lot!
 
Upvote 0
If you did not want to introduce another another column to your formal table, and given you mentioned the possibility of vba, you could try this with a copy of your workbook (after checking/adjusting the table name). This will replace the original data in the 'COMMENT' column. I have assumed the table will be on the active sheet when the code is run.

VBA Code:
Sub Employee_Name()
  With Range("Table1[COMMENT]")
    .Value = Evaluate("substitute(" & .Address & ",""Employee"",textafter(" & Range("Table1[FULL NAME]").Address & ","" ""))")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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