Avatar of SurendraJG
SurendraJGFlag for United States of America

asked on 

Extract string from excel column and lookup with other colum and find description from yet antoher colum and put it at required column

Col A                                     Col B          Col C              Col D            Col E                               Col F
<Id>str1234</Id>                                                           Desc          Description        Description of message        
<Desc>xxxx</Desc>                                                       Id              Identification      Identification of Message

The above data exists in Excel columns. Column A has 500 records but col D,E,F has 10000+ records. i need to extract Tag string from Colum A and look in the col D and find its values in Column E and F. Put those E and F values in Col B and C. I guess we need to write macro. could you please share sample code.
Microsoft Excel

Avatar of undefined
Last Comment
SurendraJG
Avatar of gplana
gplana
Flag of Spain image

What I would do is:

1. Start recording a macro
2. Do the action for first row
3. Go to next row
4. Stop the recording of the macro
5. Modify the macro by adding a loop (probably a for with the number of rows).

If you want, I can do this for you, but I think it's better to teach you how to make it by yourself.

Hope it helps. Regards.
Avatar of SurendraJG
SurendraJG
Flag of United States of America image

ASKER

This is my first macro. Could you provide that code
Avatar of gplana
gplana
Flag of Spain image

Sorry, but it's not clear what should the code do. I understand I have to extract the value between tabs <Id> and </Id> from column A, then find this value on column D (but for all rows or just on the current row?), and then if a value is found copy the entire string from E to B and from F to C on the same row where tag has been found in column D.

Is that right?
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Once you can extract the value from column A values, the rest is a VLOOKUP:

Col B formula =VLOOKUP(String,D:F,2,False)
Col C formula =VLOOKUP(String,D:F,3,False)

The only difference you will notice is the 2 and 3; these return results from the second and third column of the range D to F.

If you can be more specific how the value in column A matches the values in column D we can no doubt use text functions to extract the required string.

Thanks
Rob
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Also, some sample data would help.
Avatar of SurendraJG
SurendraJG
Flag of United States of America image

ASKER

Column 'A'  has XML Tags. For Example: <Id>str1234</Id> .We need to extract String: Id  from <Id>  not from str123 or not from </Id>. Colum D will have XML Tag name: Id which is with out < >. Colum E will have name of that particular Tag like "Identification". And  F will have description of Tag like "Identification of Message" . Column 'A'  has 500 records  for which Name and Descriptions will not exist on the same row in Column 'D' , 'E' and 'F' but we need to search entire sheet and find Name and Description from colum 'E' and 'F'  and Put E value in to Column 'B' and 'F' Value in 'C'.In the excel first row    then find this value on column D (for all rows ) and there will be some duplicates on column D, and then if a value is f'ound copy the entire string from E to B and from F to C on the same row where tag has been found In Column 'A'.

Col A                                     Col B          Col C              Col D            Col E                               Col F
 <Id>str1234</Id>                                                           Desc          Description        Description of  MSG        
 <Desc>xxxx</Desc>                                                       Id              Identification      Identification of MSG

                                                                                           Account     Account              Account of customer
                                                                                           Agent          Agent                  Agent for customer
                                                                                           ID                 Identification    Identification of MSG

                                                                                           Desc           Description         Description of MSG
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Will Id be fixed legth?
Will it always start character 2; ie after the first <?
Avatar of SurendraJG
SurendraJG
Flag of United States of America image

ASKER

The length of Id in Column"A" will be same as Column "D" . But next row in the column "A" data will be different length than previous record as it is different Tag.It can start right after "<"  but there will be blanks before "<"  in the cell. For example: <AdrTp>ADDR</AdrTp>, we need to extract AdrTP from <AdrTP>   not from </AdrTp>. Some more sample data as follows.

                Column A                                            Column D                            Column E
          <Nm>str1234</Nm>                                     Id                                         Identification
        <PstlAdr>                                                     Nm                                  Name
          <AdrTp>ADDR</AdrTp>                           ClssTp                                  ClassType
          <Dept>str1234</Dept>                           UmbrllNm                           UmbrellaName
          <SubDept>str1234</SubDept>            CtryOfDmcl                          CountryOfDomicile
          <StrtNm>str1234</StrtNm>                  RegdDstrbtnCtry                  RegisteredDistributionCountry
          <BldgNb>str1234</BldgNb>                  DnmtnCcy                          DenominationCurrency
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

So for your first example above

<Nm>str1234</Nm>

Using the MID function would extract Nm. Using the VLOOKUP with Nm would then find Nm in column D and give Name from column E
Avatar of SurendraJG
SurendraJG
Flag of United States of America image

ASKER

Thanks for Help
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo