Extract characters from a cell using VBA

Kurt

Well-known Member
Joined
Jul 23, 2002
Messages
1,664
I am trying to extract another set of characters from this same line:

Code:
MECH~CDA-CUP-PF~1 - CUP0915.2XL - Copper Reducer (P)

Code:
AddFormula TopLeft.Offset(1, 2).Resize(RowCount, 1), "=IFERROR(MID(AA" & Row & ",FIND(""`"",AA" & Row & ")+1,FIND(""~"",AA" & Row & ")-1-FIND(""`"",AA" & Row & ")),"""")"

In this piece of code I need to extract the CDA. I have tried changing the character to match the - but no luck so far.

Any ideas?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The formula should be like
=MID(A1, FIND("~",A1)+1,FIND("-",A1)-FIND("~",A1)-1)
 
Upvote 0
When I try to add it like this:

Code:
    AddFormula TopLeft.Offset(1, 2).Resize(RowCount, 1), "=IFERROR(MID(A1,FIND("~",AA)+1,FIND("-",AA)-FIND("~",AA)-1)"

I get the error invalid character on the ~
 
Upvote 0
I added another set of double quotes but the formula is still not working.
 
Upvote 0
You'll need to add the Rows in like your original formula
 
Upvote 0
Yes that is correct. I am still getting an error on this code.

The code uses AA because I am doing some other manipulation with the rest of the code in this module, just FYII.

Code:
    AddFormula TopLeft.Offset(1, 2).Resize(RowCount, 1), "=IFERROR(MID(AA" & Row & ",FIND(""-"",AA" & Row & ")+1,FIND(""~"",AA" & Row & ")-1-FIND(""-"",AA" & Row & ")),"""")"
 
Upvote 0
I just got it to work using this line of code:

Code:
     AddFormula TopLeft.Offset(1, 2).Resize(RowCount, 1), "=IFERROR(LEFT(AA" & Row & ",FIND(""-"",AA" & Row & ")-1),"""")"

Thanks for your efforts Fluff!! :)
 
Upvote 0
One more item I need to add to the formula.

I need to add the third set of info in this data:

Code:
MECH~CDA-CUP-PF~1 - CUP0915.2XL - Copper Reducer (P)

I need this code to display the MECH~CDA-CUP part of that string.

Code:
AddFormula TopLeft.Offset(1, 2).Resize(RowCount, 1), "=IFERROR(LEFT(AA" & Row & ",FIND(""-"",AA" & Row & ")-1),"""")"
 
Upvote 0
will it always be three letters?
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

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