How to add a column of to the end of columns with value from table with VBA

I have the attached workbook.

I need help with the followings.  the solution i need is via VBA, not formula.

 on the Sheet("Data") at the end of column meaning the next available column, insert column returning Description from the table for the PRODUCT column.
Flora EdwardsMedicineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rob HensonFinance AnalystCommented:
Try this formula in column E:

=IFERROR(VLOOKUP(C2,'Lookup Table'!$A$1:$B$6,2,FALSE),VLOOKUP(LEFT(C2,1)&"*",'Lookup Table'!$A$1:$B$6,2,FALSE))

This does two VLOOKUP formulas, the first takes the whole of the product column and checks the lookup table for that value and returns the value from the second column of the lookup table; if the first VLOOKUP gives an error, it takes the first character of the product and adds "*" and then looks for that value in the lookup table.

With your data, there are two lines that give an error. They are both product code beginning with 1 which doesn't show in the lookup table.

Flora EdwardsMedicineAuthor Commented:
Thanks Rob.  appreciate your support.  I needed this in VBA to automatically insert the value on the last available column.
Rob HensonFinance AnalystCommented:
OK, sorry missed that. Is there a particular reason that you need VBA?

If you convert the data list to a Table, the formula will automatically get added to new entries.

Also noticed that the values starting with 2 that are not listed specifically default to "Bad Debts" because that is the first entry that starts with 2.

What result should the non-specific 2* products get?
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Flora EdwardsMedicineAuthor Commented:
non specific should result "Not Application"

i need VBA becuase that is part of my application
Rob HensonFinance AnalystCommented:
Might take me some time to put together the VBA to do this as I am tied up with other work.

Other Experts will no doubt contribute in the meantime.


pls try
Sub macro()
Set ShD = Sheets("Data")
intProductCol = Split(Range("dataPRODUCT").Address, "$")(1)
FirstFreeCol = ShD.Cells(1, Columns.Count).End(xlToLeft).Column + 1
Set Rng = Range(ShD.Cells(2, FirstFreeCol), ShD.Cells(ShD.Range("a" & Rows.Count).End(xlUp).Row, FirstFreeCol))
Rng.Formula = "=IFERROR(VLOOKUP(" & intProductCol & "2,'Lookup Table'!$A$1:$B$6,2,FALSE),VLOOKUP(LEFT(" & intProductCol & "2,1)&""*"",'Lookup Table'!$A$1:$B$6,2,FALSE))"
Rng.Value = Rng.Value

End Sub

Open in new window

EDIT corrected


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Flora EdwardsMedicineAuthor Commented:
thanks very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.