Combining vlookup and replace-like function?

Smeghead

New Member
Joined
Mar 12, 2013
Messages
35
I have a report with a SQL query which brings up some results with one "user" column which is literally just "user01, user02, user03" etc. among other names.


I'd like to add a "user_actual" sheet to do a vlookup against, so it'd just be 2 columns with "user, actual name" and allow the report user to specify who is actually using that login, i.e. user01 - John, user03 - Mary, user06 - Dave


On the main sheet, I'd like to add a column which is basically a vlookup of the user column value (on the main sheet) against the user_actual sheet. If the "actual name" has a value, then on the main sheet user column, show the username in the format of [USER (ACTUAL NAME], (e.g. "user01 (John)"), otherwise just show the user value. Hopefully this all makes sense?





Current main sheet

USER (from SQL query)ITEMQTY
USER01aaa1
USER03aaa1
USER05bbb1
DAVEccc2
MIKEaaa2
USER02aaa1
USER06aaa1

<tbody>
</tbody>













New "user_actual" sheet

USERACTUAL NAME
USER01
USER02
USER03BART
USER04
USER05LEE
USER06MARY

<tbody>
</tbody>











Final desired:

USER (new column)ITEMQTYUSER (from SQL query)
USER01aaa1USER01
USER03 (BART)aaa1USER03
USER05 (LEE)bbb1USER05
DAVEccc2DAVE
MIKEaaa2MIKE
USER02aaa1USER02
USER06 (MARY)aaa1USER06

<tbody>
</tbody>
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi Smeghead,

Here's a formula you can try...


Excel 2016 (Windows) 32 bit
ABCD
1USERITEMQTYUSER (from SQL query)
2USER01aaa1USER01
3USER03 (BART)aaa1USER03
4USER05 (LEE)bbb1USER05
5DAVEccc2DAVE
6MIKEaaa2MIKE
7USER02aaa1USER02
8USER06 (MARY)aaa1USER06
Sheet1
Cell Formulas
RangeFormula
A2=D2 & IFERROR(SUBSTITUTE(" (" & VLOOKUP(D2,UserLookup!A:B,2,0) & ")"," ()",""),"")



Depending on how you are pulling your SQL query, you could possibly achieve the same result without a formula by modifying the query or using the Data Model.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,495
Messages
6,130,979
Members
449,611
Latest member
Bushra

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