SOLVED

Help to modify a SUBSTITUTE(MID(LEFT formula so it works as expected.

%3CLINGO-SUB%20id%3D%22lingo-sub-2266748%22%20slang%3D%22en-US%22%3EHelp%20to%20modify%20a%20SUBSTITUTE(MID(LEFT%20formula%20so%20it%20works%20as%20expected.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2266748%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20Excel%20formula%20below%20looks%20at%20%3CSTRONG%3ECell%20A1%3C%2FSTRONG%3E%20in%20a%20worksheet%20called%20%3CSTRONG%3EFolderDataImport.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EIt%20searches%20the%20data%20in%20Cell%20A1%20and%20locates%20the%20%E2%80%9C-%E2%80%9C%20character%2C%20of%20which%20there%20is%20only%20ever%20one%2C%20and%20then%20looks%20for%20the%20%E2%80%9C%5B%E2%80%9C%20character%2C%20again%20there%20will%20only%20ever%20be%20one%2C%20then%20it%20returns%20what%20ever%20data%20is%20between%20those%20two%20characters%20and%20is%20then%20copied%20down%20the%20column%20for%20as%20long%20as%20data%20exists%20in%20the%20FolderDataImport!A%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBecause%20there%20are%20multiple%20columns%2C%20each%20of%20which%20has%20different%20data%20to%20be%20processed%2C%20I%20use%20a%20VBA%20module%20to%20enter%20all%20of%20the%20formulas.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20modify%20the%20formula%20for%20use%20in%20a%20different%20column%20to%20do%20the%20following%3A%3C%2FP%3E%3CP%3ELook%20at%20%3CSTRONG%3EFolderDataImport!A1%3C%2FSTRONG%3E%2C%20locate%20the%20%E2%80%9C%3CSTRONG%3E-%3C%2FSTRONG%3E%E2%80%9C%20character%20and%20the%20%E2%80%9C%3CSTRONG%3E%5B%3C%2FSTRONG%3E%E2%80%9C%20character%20and%20then%20check%20if%20the%20%E2%80%9C%3CSTRONG%3E(%3C%2FSTRONG%3E%E2%80%9C%20and%20%E2%80%9C%3CSTRONG%3E%3CU%3E)%3C%2FU%3E%3C%2FSTRONG%3E%E2%80%9D%20characters%20exist%20in-between%20them.%20If%20the%20do%20then%20return%20what%20ever%20is%20between%20the%20%E2%80%9C%3CSTRONG%3E(%3C%2FSTRONG%3E%E2%80%9C%20and%20%E2%80%9C%3CSTRONG%3E)%3C%2FSTRONG%3E%E2%80%9D%20but%20not%20the%20%E2%80%9C%3CSTRONG%3E(%3C%2FSTRONG%3E%E2%80%9C%20and%20%E2%80%9C%3CSTRONG%3E)%3C%2FSTRONG%3E%E2%80%9D%2C%20only%20the%20data%20between%20them.%20If%20the%20%E2%80%9C%3CSTRONG%3E(%3C%2FSTRONG%3E%E2%80%9C%20and%20%E2%80%9C%3CSTRONG%3E)%3C%2FSTRONG%3E%E2%80%9D%20characters%20are%20NOT%20found%20then%20do%20nothing%20(so%20the%20cell%20appears%20blank).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20the%20modified%20would%20work%20thus%3A%3C%2FP%3E%3CP%3EAAAA%20%E2%80%93%20BBBB%20(1234)DDDD%20%5B0000%5DFFFF%20returns%20%E2%80%9C%3CSTRONG%3E1234%3C%2FSTRONG%3E%E2%80%9D%3C%2FP%3E%3CP%3EBut%3C%2FP%3E%3CP%3EAAAA%20%E2%80%93%20BBBB%201234%20DDDD%20%5B0000%5DFFFF%20returns%20%3CSTRONG%3Enothing%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20SWs%20As%20Worksheet%2C%20TWs%20As%20Worksheet%3C%2FP%3E%3CP%3EDim%20Lr%20As%20Long%3C%2FP%3E%3CP%3EDim%20Answer%3C%2FP%3E%3CP%3ESet%20SWs%20%3D%20Worksheets(%22FolderDataImport%22)%3C%2FP%3E%3CP%3ESet%20TWs%20%3D%20Worksheets(%22Pack%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETWs.Range(%22D2%3AD%22%20%26amp%3B%20Lr%20%2B%201).Formula%20%3D%20%22%3DIF(FolderDataImport!A1%3D%22%22%22%22%2C%22%22%22%22%2CSUBSTITUTE(MID(LEFT(FolderDataImport!A1%2CFIND(%22%22%5B%22%22%2CFolderDataImport!A1)-2)%2CFIND(%22%22-%22%22%2CFolderDataImport!A1)%2B3%2CLEN(FolderDataImport!A1))%2C%22%22_%22%22%2C%22%22%20%22%22))%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20grateful%20for%20any%20assistance%20as%20this%20is%20beyond%20my%20skills.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20to%20format%20the%20above%20as%20code%20but%20I%20am%20unsure%20if%20it%20worked.%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2266748%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

The Excel formula below looks at Cell A1 in a worksheet called FolderDataImport.

It searches the data in Cell A1 and locates the “-“ character, of which there is only ever one, and then looks for the “[“ character, again there will only ever be one, then it returns what ever data is between those two characters and is then copied down the column for as long as data exists in the FolderDataImport!A column.

 

Because there are multiple columns, each of which has different data to be processed, I use a VBA module to enter all of the formulas.

 

I am trying to modify the formula for use in a different column to do the following:

Look at FolderDataImport!A1, locate the “-“ character and the “[“ character and then check if the “(“ and “)” characters exist in-between them. If the do then return what ever is between the “(“ and “)” but not the “(“ and “)”, only the data between them. If the “(“ and “)” characters are NOT found then do nothing (so the cell appears blank).

 

So the modified would work thus:

AAAA – BBBB (1234)DDDD [0000]FFFF returns “1234

But

AAAA – BBBB 1234 DDDD [0000]FFFF returns nothing

 

 

Dim SWs As Worksheet, TWs As Worksheet

Dim Lr As Long

Dim Answer

Set SWs = Worksheets("FolderDataImport")

Set TWs = Worksheets("Pack")

 

TWs.Range("D2:D" & Lr + 1).Formula = "=IF(FolderDataImport!A1="""","""",SUBSTITUTE(MID(LEFT(FolderDataImport!A1,FIND(""["",FolderDataImport!A1)-2),FIND(""-"",FolderDataImport!A1)+3,LEN(FolderDataImport!A1)),""_"","" ""))"

 

I would be grateful for any assistance as this is beyond my skills.

 

I tried to format the above as code but I am unsure if it worked.,

 

Thank you in advance.

2 Replies
best response confirmed by Belinea2010 (Occasional Contributor)
Solution

@Belinea2010 

Try

 

TWs.Range("D2:D" & Lr + 1).Formula = "=IF(ISNUMBER(FIND(""["",FolderDataImport!A1,FIND("")"",FolderDataImport!A1,FIND(""("",FolderDataImport!A1,FIND(""-"",FolderDataImport!A1)+1)+1)+1)),MID(FolderDataImport!A1,FIND(""("",FolderDataImport!A1,FIND(""-"",FolderDataImport!A1)+1)+1,FIND("")"",FolderDataImport!A1,FIND(""("",FolderDataImport!A1,FIND(""-"",FolderDataImport!A1)+1)+1)-FIND(""("",FolderDataImport!A1,FIND(""-"",FolderDataImport!A1)+1)-1),"""")"

Hi Hans.

Thank you for your kind reply and code.
It works perfectly and you have really helped out.

Thanks Again.