TheRedCardinal
Active Member
- Joined
- Jul 11, 2019
- Messages
- 252
- Office Version
- 365
- 2021
- Platform
- Windows
I have the following requirements:
I've run into a couple of problems.
The first is based on finding the unique values. I put together this code:
This works fine when on the WS2 worksheet (WS2 has been set earlier) but it doesn't work when either calling the sub from a button, or running it in VBA when another sheet is selected.
As I need to expand the formula to include the second sheet, I don't know what is going wrong with the above that it is only looking up the current active sheet.
Next stage is to create an array which is (y x 3) for my 2 additional pieces of info.
I want to lookup each unique value in a table called "TaxCodeDetails" in the column called "Tax Code" and then return into the 2nd column of the array the corresponding description.
This became my code:
This time the error is a compile error telling me I need a separator or ")" and then highlights the "[[#Headers],[Tax Code]]" section of the line which looks complete to me.
So my 2 questions are:
- Look through 2 columns on 2 different sheets
- Identify all of the unique values in those 2 columns
- From that list then check a table in the workbook and add further details sourced from that table
I've run into a couple of problems.
The first is based on finding the unique values. I put together this code:
VBA Code:
Set ObjDict = CreateObject("Scripting.Dictionary")
TaxCodeArray = Application.Transpose(WS2.Range("C2", Cells(Rows.Count, "C").End(xlUp)))
For Counter = 1 To UBound(TaxCodeArray, 1)
ObjDict(TaxCodeArray(Counter)) = 1
Next
This works fine when on the WS2 worksheet (WS2 has been set earlier) but it doesn't work when either calling the sub from a button, or running it in VBA when another sheet is selected.
As I need to expand the formula to include the second sheet, I don't know what is going wrong with the above that it is only looking up the current active sheet.
Next stage is to create an array which is (y x 3) for my 2 additional pieces of info.
I want to lookup each unique value in a table called "TaxCodeDetails" in the column called "Tax Code" and then return into the 2nd column of the array the corresponding description.
This became my code:
VBA Code:
TaxCodeArray(Counter,2) = Index(TaxCodeDetails[[#Headers],[Tax Code]], Match(TaxCodeArray(Counter,1), TaxCodeDetails[#Headers],[Description]], False))
This time the error is a compile error telling me I need a separator or ")" and then highlights the "[[#Headers],[Tax Code]]" section of the line which looks complete to me.
So my 2 questions are:
- Is this method just too clunky (I will eventually output the array to a worksheet)
- What is going wrong with my Index/Match function?