vlookup, index &match or other?

excel01noob

Board Regular
Joined
Aug 5, 2019
Messages
93
Office Version
  1. 365
  2. 2016
Hi

I'm having a bit of hard time trying to figure out how to solve this.
I have two table, table 1 is the registered invoices for a particular month where I could have old customer accounts (more than 5 digits - column D), newer accounts have only 5 digits as account number (column ACCT_ID - table 1)

I need to prepare report where I combine both account numbers. where for the old ones, I need to get a REGIST number that comes from table 2 (this is actually a table saved in a separate file).

Under column "result" I want to have the accounts with this format:

-new accounts: starting with N and then the 5-digits account and three zeros (example: acc 27193 is N27193000);
-old accounts: they need to start by O then the first 4 digits and year when opened. This I take from table 2 (example: both accounts 7268999 and 7268111 will have the same first 4 digits which as per table 2 gives REGIST F72682001


I have tried to combine If, left, len, vlookup but end up not getting it right.
What do you advise me to do?


this is just the first step prior to implement a VBA later..

TRANS_TYPARTICVALUEDTACCT_IDAMMTRESULT?MANDTACCT_IDLEG_ACCTREGIST
INVCAS3225TF2021-05-03T00:00:00.000000
7268999​
22564​
0107268000F72682001
INVCHE1174WE2021-05-04T00:00:00.000000
4043111​
1005.99​
0104043002F40431985
INVCHE459DE2021-05-08T00:00:00.000000
7268111​
1985.43​
0104482283F44821989
INVCAS287SY2021-05-11T00:00:00.000000
4482999​
34.5​
0107004204F70041978
INVCAS1174WE2021-05-11T00:00:00.000000
26725​
2569.52​
0101005000F10091993
INVACC133LO2021-05-13T00:00:00.000000
7268000​
875.44​
0101005080F10091993
INVACC459DE2021-05-13T00:00:00.000000
27194​
224.55​
0101005203F10091993
INVCHE117RE2021-05-28T00:00:00.000000
7004111​
103298.5​
INVCHE287SY2021-05-28T00:00:00.000000
27193​
1433.99​
TABLE 1TABLE 2
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Can you put a desired result in the result column. I'm having trouble visualizing this as I don't see a column with the year opened in it. That being said, the easiest way I've found to deal with multiple workbooks is power query.
 
Upvote 0
the results in this case should be

O72682001
O40431985
O72682001
O44821989
N26725000
O72682001
N27194000
O70041978
N27193000
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDEFGHIJK
1TRANS_TYPARTICVALUEDTACCT_IDAMMTRESULT?MANDTACCT_IDLEG_ACCTREGIST
2INVCAS3225TF2021-05-03T00:00:00.000000726899922564O72682001107268000F72682001
3INVCHE1174WE2021-05-04T00:00:00.00000040431111005.99O40431985104043002F40431985
4INVCHE459DE2021-05-08T00:00:00.00000072681111985.43O72682001104482283F44821989
5INVCAS287SY2021-05-11T00:00:00.000000448299934.5O44821989107004204F70041978
6INVCAS1174WE2021-05-11T00:00:00.000000267252569.52N26725000101005000F10091993
7INVACC133LO2021-05-13T00:00:00.0000007268000875.44O72682001101005080F10091993
8INVACC459DE2021-05-13T00:00:00.00000027194224.55N27194000101005203F10091993
9INVCHE117RE2021-05-28T00:00:00.0000007004111103298.5O70041978
10INVCHE287SY2021-05-28T00:00:00.000000271931433.99N27193000
11
Lists
Cell Formulas
RangeFormula
F2:F10F2=IF(LEN(D2)=5,"N"&D2&"000",SUBSTITUTE(VLOOKUP(LEFT(D2,4),$I$2:$K$8,3,0),"F","O"))
 
Upvote 0
If you wanted a VBA solution why didn't you say so?
 
Upvote 0
You said it was a first step prior to VBA. That is not the same.
 
Upvote 0
how to translate the "substitute" part of the formula into VBA if:

-I have the table 2 in a closed workbook which I don't need to open, location N:\My docs\Table 2 closed.xlsx;

-the table 2 data is on the same columns H to K but it is stored as text, it seems I might get an error "When searching number or date values, ensure that the data in the first column of table_array is not stored as text values. In this case, the VLookup method may give an incorrect or unexpected value."


this is what I got so far

Option Explicit

Sub accounts_old_and_new()

Dim LastRow As Long

LastRow = Range("D" & Rows.Count).End(xlUp).Row

Dim i As Long

For i = 2 To LastRow

If Len(Range("D" & i)) = 5 Then
Range("F" & i).Value = "C" & Range("D" & i)

'Else

Range("F" & i).Value = ???

Else

End If
Next i

End Sub
 
Upvote 0
Using Xl formulae in a macro is normally best avoided as it tends to be slow. I would suggest that you start a new thread, explaining that you want a macro & giving all relevant info.
 
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,772
Members
449,187
Latest member
hermansoa

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