Can you help me think this out? How would you approach it?

GregG44149

New Member
Joined
May 15, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Not sure of the best way to approach this. I have a fairly large spreadsheet that contains information below.

I want to create a function (or maybe a different approach?) that does the following:

1) Will look at column F and find the right Client Code (each client code is 3 digits, separated by semi-colon). Variable in length and number of clients. Client numbers are unique.
2) Then looks at column C and finds the correct state
3) Finally, looks at column E to confirm that expiration date is less than today.

I'm stuck because I can't break out client code in F to individual lines (spreadsheet would quickly become exponentially large with 50 states). Otherwise I would probably approach it using an array function.

ABCDEF
AGENT CODENAME1LIC STATELIC DATELIC EXP DATECLIENT
HNBLBROKER1LA
12/17/2013​
03/31/2024​
AAA;BBB;
HNBLBROKER1OH
01/01/2022​
12/31/2024​
AAA;BBB;
HNBLBROKER1TX
04/01/2022​
12/31/2027​
AAA;BBB;
KENRBROKER2GA
03/17/2020​
12/31/2024​
CCC;
JNGXBROKER3AL
07/09/2015​
07/31/2019​
FFF;ZZZ;UUU;
HBBDBROKER4CO
03/11/2019​
03/31/2024​
DDD;FFF;LLL;MMM;

Thank you in advance!
Greg
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I would do that by using a dictionary. Also if you initialise the dictionary by calling the initialise sub when the worksheet is activated the function will work as a worksheet function or you can call it from a vba sub:
VBA Code:
Public dic As Object
Sub initialise()
   Set dic = CreateObject("Scripting.dictionary")

lastcol = 6 ' column F
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, lastcol))
For i = 3 To lastrow
 cc = Split(inarr(i, 6), ";")
   For j = 0 To UBound(cc)
     dicv = inarr(i, 3) & cc(j) ' this concatenates the state and the client code
     dic(dicv) = inarr(i, 5)   ' load the dictionary with the date
    Next j
Next i
MsgBox "Dictionary initialised"
End Sub

Sub testdic()
State = "TX"
client = "AAA"
tttt = finddate(State, client)
 MsgBox tttt
End Sub

Function finddate(State As Variant, client As Variant)
 Dim tt As String
 tt = State & client
 ttc = dic(tt)
 finddate = ttc

End Function
 
Upvote 0
Is this what you mean? If not please give examples of the results that you expect and explain why those results.

GregG44149.xlsm
CEFGHIJ
1LIC STATELIC EXP DATECLIENTClientStateExpired
2LA31/03/2024AAA;BBB;ZZZALTRUE
3OH31/12/2024AAA;BBB;AAATXFALSE
4TX31/12/2027AAA;BBB;FFFALTRUE
5GA31/12/2024CCC;MMMTXFALSE
6AL31/07/2019FFF;ZZZ;UUU;
7CO31/03/2024DDD;FFF;LLL;MMM;
8
Sheet1
Cell Formulas
RangeFormula
J2:J5J2=COUNTIFS(F:F,"*"&H2&"*",C:C,I2,E:E,"<"&TODAY())>0
 
Upvote 0
I would do that by using a dictionary. Also if you initialise the dictionary by calling the initialise sub when the worksheet is activated the function will work as a worksheet function or you can call it from a vba sub:
VBA Code:
Public dic As Object
Sub initialise()
   Set dic = CreateObject("Scripting.dictionary")

lastcol = 6 ' column F
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, lastcol))
For i = 3 To lastrow
 cc = Split(inarr(i, 6), ";")
   For j = 0 To UBound(cc)
     dicv = inarr(i, 3) & cc(j) ' this concatenates the state and the client code
     dic(dicv) = inarr(i, 5)   ' load the dictionary with the date
    Next j
Next i
MsgBox "Dictionary initialised"
End Sub

Sub testdic()
State = "TX"
client = "AAA"
tttt = finddate(State, client)
 MsgBox tttt
End Sub

Function finddate(State As Variant, client As Variant)
 Dim tt As String
 tt = State & client
 ttc = dic(tt)
 finddate = ttc

End Function

Thank you! Wasn't aware of this approach AND this will assist me on another issue I'm having. Thanks again!
 
Upvote 0
Is this what you mean? If not please give examples of the results that you expect and explain why those results.

GregG44149.xlsm
CEFGHIJ
1LIC STATELIC EXP DATECLIENTClientStateExpired
2LA31/03/2024AAA;BBB;ZZZALTRUE
3OH31/12/2024AAA;BBB;AAATXFALSE
4TX31/12/2027AAA;BBB;FFFALTRUE
5GA31/12/2024CCC;MMMTXFALSE
6AL31/07/2019FFF;ZZZ;UUU;
7CO31/03/2024DDD;FFF;LLL;MMM;
8
Sheet1
Cell Formulas
RangeFormula
J2:J5J2=COUNTIFS(F:F,"*"&H2&"*",C:C,I2,E:E,"<"&TODAY())>0
I learn something new.... everyday. Bingo, this is the simplest approach for me!
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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