简体   繁体   中英

VBA Excel wildcard string search, copy and paste to new cell

I am looking for help in trying to do the following.

I have large amount of data in Excel (100K+ rows) which have many columns, in one of the columns (lets just say col A) there is a string of data in each cell that lists file path info indicating a java installation. I need to search within that string to find common characters that start and end the same but will have different data in-between, so wildcard would be needed to identify. After identifying the data in the string search for each cell in the specified column (col A) I need to copy and paste the data identified to a different column located just right of the data (col B) on same worksheet for each row. So would look something like this:

Example

COLUMN A (original data string)
C:\\app\\Java\\jre7\\bin\\...
C:\\Program Files (x86)\\Java\\jre6\\bin\\...
C:\\app\\JAVA\\jdk1.7.0._21\\jre\\bin\\...
C:\\JAVA\\JDK-1_5_0_16_i586\\jre\\bin\\...

COLUMN B (copy & paste to here)
jre7
jre6
jdk1.7.0._21
JDK-1_5_0_16_i586

Would need wildcard search to pick up anything specific between the \\ & \\ that starts with letter j and would be followed by two letters which could be re or dk but would have to allow for character or number to follow this in any length. Would be something like \\j??*#*\\ for the search always starting with same first two characters, followed by two letters, then possibly another character or nothing at all before a version number, then can be no characters or many after the version number.

As you can see from examples I am trying to pick up the version info with version numbers in them and do not want to get dir info with jre or jdk only in them, since most of my data have these dir listed somewhere in the file path string.

Then copying this info and pasting into Col B as shown in example is what I am trying to do.

Any help would be greatly appreciated as this is a manual process that would benefit greatly from automating.

There's actually a really quick way to do this using formulas. You could combine all of these into one formula if you wish, but I spread it into four simple formulas with the fourth giving you the answer.

Assuming the first string is in cell A1:

B1 = =SEARCH("java",A1)

C1 = =FIND("\\",A1,E1)

D1 = =FIND("\\",A1,F1+1)

E1 = =MID(A1,F1+1,G1-F1-1)

E1 will have your answer. Autofill down the columns and then copy>paste values in column E and delete columns BD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM