Formula Help Please

SARABECK

Board Regular
Joined
Jan 5, 2012
Messages
132
Hi Everyone,
I have truck ids that comes through the ledger with their appropriate sales and purchase dollars. The dollars should offset when a sale and purchase IDs are the same. However, the issues i'm running into is spaces in between, zeros in between, letters in the beginning and letters in the end for these truck IDs.

I use the 2 formulas below to help but it is not capturing everything.

Formula 1 - To remove all the D in front.
Code:
=IF(LEFT(B2,2)="D*",RIGHT(B2,LEN(B2)-2),IF(RIGHT(B2,1)="D",LEFT(B2,LEN(B2)-1),B2))

Formula 2 - To remove extra spaces in between.
Code:
=SUBSTITUTE(C8," ","")



Truck IDsFormula 1Formula 2Problems
SaleACL123ACL123Letter in the Front
PurchD*ACL123ACL123Letter in the Front
SaleABC 329ABC 329ABC329Letter in the Front and SPACE - No Match
PurchD*ABC329ABC329ABC329Letter in the Front and SPACE - No Match
SaleABC 35060BABC 35060BABC35060BLetter in the Front, SPACE and LETTER B - No Match
PurchD*ABC35060ABC35060ABC35060Letter in the Front, SPACE and LETTER B - No Match
SalePVHC20BPVHC20BPVHC20BLetter in the Front and in the end - No Match
PurchD*PVHC20PVHC20PVHC20Letter in the Front and in the end - No Match
SaleCC 01116CC 01116CC01116Letter in the Front, SPACE and ZERO in between
PurchD*CC1116CC1116CC1116Letter in the Front, SPACE and ZERO in between
SaleGOPV 036BGOPV 036BGOPV036BLetter in the Front, SPACE, ZERO IN BETWEEN (need to remove B)
PurchD*GOPV36BGOPV36BGOPV36BLetter in the Front, SPACE, ZERO IN BETWEEN (need to remove B)
SalePVBL0099PVBL0099PVBL0099Letter in the Front, Zeros in Between
PurchD*PVBL99PVBL99PVBL99Letter in the Front, Zeros in Between

<tbody>
</tbody>


Thank you.

Please delete my other "Formula Needed" topic. I submitted this again as my original topic was not loading probably. My apologizes.
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Thank you for quick reply. This is not vlookup. I need a formula the will remove these things in the IDs.
Someone please help. I need the sale and purchase IDs to match.
Thank you
 
Upvote 0
It matched the codes in your sample:


Excel 2010
ABCDEF
1TypeNameTypeName
2PurchDACL123ACL123SalePVHC20B
3PurchDABC329ABC 329SaleABC 329
4PurchDABC35060ABC 35060BSalePVBL0099
5PurchDPVHC20PVHC20BSaleCC 01116
6PurchDCC1116CC 01116SaleGOPV 036B
7PurchDGOPV36BGOPV 036BSaleABC 35060B
8PurchDPVBL99PVBL0099SaleACL123
Sheet2
Cell Formulas
RangeFormula
C2=fuzzyvlookup(B2,$F$2:$F$8,1)


That should work for what you're trying to do
 
Upvote 0
Thank you sheetspread. Can you please help and show how i can set this up?

Will this work if the sale and purchases are only known by their IDs. I mean, For easy illustration, i added the sale and purchase column, otherwise, it shows up in the report as ABC 329 in row 3 colum A (for example) and D*ABC329 on row 150 column A.

I thought if i have formula i can drag it down and then do a conditional formatting for duplicated and it should offset.

Thank you so much.




 
Last edited:
Upvote 0
My formula is incomplete:

Original IDs:

GOPV 036D
D*GOPV36D
My formulas:
1:=IF(LEFT(B65,2)="D*",RIGHT(B65,LEN(B65)-2),IF(RIGHT(B65,1)="D",LEFT(B65,LEN(B65)-1),B65))
2:=SUBSTITUTE(C65," ","")
3:=LEFT(D66,LEN(D66)-(RIGHT(D66)="D"))

<tbody>
</tbody>


Results:
GOPV036
GOPV36

I need help to get rid of the zero in between. so that it is an exact match.

Thank you.
 
Last edited:
Upvote 0
Copy Alan's code from post #2 of the link, paste it into a module, and the formula will work. I think you do need the Purchases/Sales column and set up the table like I did above with a column C header like "Common ID" to use as your standard. Then each line will have the same code and you can apply CF from there.
 
Last edited:
Upvote 0
You could try this user-defined function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

If it fails for any data, please provide samples of that data and the expected results.

Rich (BB code):
Function TruckID(s As String) As String
  With CreateObject("VBScript.RegExp")
    .Pattern = "^(D\*)?(\D+)(0*)(\d+)(\D)?$"
    TruckID = .Replace(Replace(s, " ", ""), "$2$4")
  End With
End Function


Excel Workbook
BC
1Truck IDsExtracted ID
2ACL123ACL123
3D*ACL123ACL123
4ABC 329ABC329
5D*ABC329ABC329
6ABC 35060BABC35060
7D*ABC35060ABC35060
8PVHC20BPVHC20
9D*PVHC20PVHC20
10CC 01116CC1116
11D*CC1116CC1116
12GOPV 036BGOPV36
13D*GOPV36BGOPV36
14PVBL0099PVBL99
15D*PVBL99PVBL99
Truck IDs
 
Upvote 0
Peter_SSs, Thank you so much! Just awesome! thank you!!.

Peter_SSs, I would like to apply this to my Rail IDs, the concept is the same except the Rail IDs starts with B in stead of D. Please don't add to this coding i would like to keep them separate.

I try to change the coding below but not working for me.

Code:
Function TruckID(s As String) As String
  With CreateObject("VBScript.RegExp")
 [B]   .Pattern = "^(B\*)?(\B+)(0*)(\b+)(\B)?$" [/B]
 [B]  TruckID = .Replace(Replace(s, " ", ""), "$2$4") [/B]
  End With
End Function

Thank you again.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,608
Members
449,174
Latest member
ExcelfromGermany

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