cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

How to vlookup data from 2 excel file in Pad?

Hi Team,

 

I have 2 excel file which contains almost 10k records.

 

EmpData - Excel and 

IncidentExcel 
__________________________________________________________________

 

IncidentExcel has bellow columns

NumberCallerEmailEmployee numberStateAssignment groupAssigned toEmailEmployee numberShort descriptionDescriptionCategoryPriorityImpactUrgencyOpenedUpdatedUpdated bySLA dueResolvedResolved byResolution codeResolution notesResolve timeMade SLALocationDomainClosedClosed byChild IncidentsBusiness resolve timeAdditional commentsWork notesUpdatesTime workedSubcategoryServiceReassignment countDomainOn hold reasonUser ID

Adding new columns in every time Incident excel - those columns are 

  • ITLT, ITSLT, BU, Department, Work Area, Office City, Email ID.

- Emp excel has this column data 

 

Employee IdFull NameITLTIT SLTBusiness UnitDepartmentWork AreaOffice CityEmail IdStatus

Now i want write this data including columns ( 

  • ITLT, ITSLT, BU, Department, Work Area, Office City, Email ID.) 
    in IncidentExcel file by using email id

Thank you so much in advance

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @VishnuReddy1997 
I have made few changes and its working as expected. 
Thank you so much!!! 

View solution in original post

Hi @Sanket1 ,

 

Great to hear. Please except my reply as a solution so it will help others in the future.

 

Regards,

Vishnu Reddy

View solution in original post

12 REPLIES 12

Hi @Sanket1 ,

 

I have provided few sample methods how to can achieve Vlook UP in PAD.

 

Method 1: 

You try with PAD action as shown below.

VishnuReddy1997_0-1720095358766.png

 

Code:

Excel.Attach DocumentName: $'''VL.xlsx''' Instance=> ExcelInstance
Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Sheet2'''
Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: $'''=VLOOKUP(A2,Sheet1!A:B,2,FALSE)''' Column: $'''B''' Row: 2
Excel.CopyCellsFromExcel.CopyCell Instance: ExcelInstance StartColumn: $'''B''' StartRow: 2
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
Excel.SelectCellsFromExcel.SelectCells Instance: ExcelInstance StartColumn: $'''B''' StartRow: 2 EndColumn: $'''B''' EndRow: FirstFreeRow - 1
MouseAndKeyboard.SendKeys.FocusAndSendKeysByInstanceOrHandle WindowInstance: ExcelInstance TextToSend: $'''{Control}({V})''' DelayBetweenKeystrokes: 10 SendTextAsHardwareKeys: False

 

Method 2:

You can try with VBscript as shown below.

 

VBscript Code:

Const xlUp = -4162
Dim columnToConvert
Const sourceExcelFile = "%Mouser_BOM_Files[0]%"
Const destinationExcelFile = "%Output_Files[0].FullName%"

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = True

Set objSourceWorkbook = objExcel.Workbooks.Open(sourceExcelFile)
Set objDestinationWorkbook = objExcel.Workbooks.Open(destinationExcelFile)

Set objSourceWorksheet = objSourceWorkbook.Sheets(1)
Set objDestinationWorksheet = objDestinationWorkbook.Sheets(1)

sourceLastRow = objSourceWorksheet.Cells(objSourceWorksheet.Rows.Count, "A").End(xlUp).Row
destinationLastRow = objDestinationWorksheet.Cells(objDestinationWorksheet.Rows.Count, "B").End(xlUp).Row

For i = 2 To sourceLastRow
    sourceValue = objSourceWorksheet.Cells(i, 1).Value
    sourceKValue = objSourceWorksheet.Cells(i, 11).Value
    If Not IsEmpty(sourceKValue) And IsNumeric(sourceKValue) Then
        For j = 2 To destinationLastRow
            destinationValue = objDestinationWorksheet.Cells(j, 2).Value
            If sourceValue = destinationValue Then
                If sourceKValue = 0 Then
                    objDestinationWorksheet.Cells(j, 6).Value = ""
                     objDestinationWorksheet.Cells(j, 7).Value = objSourceWorksheet.Cells(i, 11).Value
                     objDestinationWorksheet.Cells(j, 8).Value = objSourceWorksheet.Cells(i, 13).Value
                     objDestinationWorksheet.Cells(j, 9).Value = objSourceWorksheet.Cells(i, 14).Value
                     
                Else
                    objDestinationWorksheet.Cells(j, 6).Value = objSourceWorksheet.Cells(i, 9).Value
                     objDestinationWorksheet.Cells(j, 7).Value = objSourceWorksheet.Cells(i, 11).Value 
                     objDestinationWorksheet.Cells(j, 8).Value = objSourceWorksheet.Cells(i, 13).Value
                     objDestinationWorksheet.Cells(j, 9).Value = objSourceWorksheet.Cells(i, 14).Value
                End If
                Exit For ' Exit the loop once a match is found in destination
            End If
        Next
    End If
Next

' Specify the column you want to convert to General format (for example, column A)
columnToConvert = "F"

' Convert the column to General format
objDestinationWorksheet.Columns(columnToConvert).NumberFormat = "General"

objSourceWorkbook.Close False
objDestinationWorkbook.Close True
objExcel.Quit

Set objSourceWorksheet = Nothing
Set objDestinationWorksheet = Nothing
Set objSourceWorkbook = Nothing
Set objDestinationWorkbook = Nothing
Set objExcel = Nothing

 

(Note:- if you got your solution you can mark as solution and gives kudos)


Thanks & Regards

Vishnu Reddy

 

I have 2 different excels so

how can I do?

 

Hi @Sanket1 ,

 

In Method 2 I have done the same. You can see in the VBscript there is 2 excel files named as Source excel file and destination excel file.

 

(Note:- if you got your solution you can mark as solution and gives kudos)


Thanks & Regards

Vishnu Reddy

Could you please vb script base on my requirement with columns name?

Apologies I did not get as much from vb script

Can you provide BOTH Excel files and can you explain full deatils if BOTH are matching ,what and all values it should pick from source file and write it in destination file. If it contains senstive data send it as private message.

Hi @Sanket1 ,

 

Can you let me know which column it should compare between 2 excels.

 

Regards,

Vishnu Reddy

Empdata Email Id And incident excel Email

Hi @Sanket1 ,

 

Please find the VBscript to do you above scenario.

Dim objExcel, objWorkbookSrc, objWorkbookDest, objSheetSrc, objSheetDest
Dim lastRowSrc, lastRowDest, i, j, srcValue, destValue

' Create an instance of Excel application
Set objExcel = CreateObject("Excel.Application")

' Open the source and destination workbooks
Set objWorkbooksrc=objExcel.Workbooks.Open("C:\Users\Desktop\Power Automate Desktop\Practice\VLOOKUP\EMP DATA.xlsx")
Set objWorkbookDest = objExcel.Workbooks.Open("C:\Users\Desktop\Power Automate Desktop\Practice\VLOOKUP\EMP.xlsx")

' Get the first worksheet in each workbook (modify as necessary)
Set objSheetsrc=objWorkbookSrc.Sheets(1)
Set objSheetDest = objWorkbookDest.Sheets(1)

' Find the last row with data in the source and destination sheets
lastRowsrc=objSheetSrc.Cells(objSheetSrc.Rows.Count, 3).End(-4162).Row ' Column C in source
lastRowDest = objSheetDest.Cells(objSheetDest.Rows.Count, 9).End(-4162).Row ' Column I in destination

' Loop through each row in the source sheet
For i = 1 To lastRowSrc
    srcValue = objSheetSrc.Cells(i, 3).Value ' Value in column C of source sheet
    
    ' Loop through each row in the destination sheet to find a match
    For j = 1 To lastRowDest
        destValue = objSheetDest.Cells(j, 9).Value ' Value in column I of destination sheet
        
        ' If a match is found, copy the data
        If srcValue = destValue Then
            objSheetSrc.Cells(i, 42).Value = objSheetDest.Cells(j, 3).Value ' Copy column C to AP
            objSheetSrc.Cells(i, 43).Value = objSheetDest.Cells(j, 4).Value ' Copy column D to AQ
            objSheetSrc.Cells(i, 44).Value = objSheetDest.Cells(j, 5).Value ' Copy column E to AR
            objSheetSrc.Cells(i, 45).Value = objSheetDest.Cells(j, 6).Value ' Copy column F to AS
            objSheetSrc.Cells(i, 46).Value = objSheetDest.Cells(j, 7).Value ' Copy column G to AT
            objSheetSrc.Cells(i, 47).Value = objSheetDest.Cells(j, 8).Value ' Copy column H to AU
            objSheetSrc.Cells(i, 48).Value = objSheetDest.Cells(j, 9).Value ' Copy column I to AV
            objSheetSrc.Cells(i, 49).Value = objSheetDest.Cells(j, 10).Value ' Copy column J to AW
        End If
    Next
Next

' Save the source workbook
objWorkbookSrc.Save

' Close the workbooks
objWorkbookSrc.Close False
objWorkbookDest.Close False

' Quit the Excel application
objExcel.Quit

' Clean up
Set objSheetsrc=Nothing
Set objSheetDest = Nothing
Set objWorkbooksrc=Nothing
Set objWorkbookDest = Nothing
Set objExcel = Nothing

 

(Note:- if you got your solution you can mark as solution and gives kudos)


Thanks & Regards

Vishnu Reddy

Hi @VishnuReddy1997 

I am trying to run above script but its running so long time , 

emp data contain 22k and incident data contain 22k records
is this reason for running long time?

Hi @Sanket1 ,

 

If there is a larger data it will take time with VBscript.

In that case You need to try with Python Code.

Please find the Python code for that . Try running it with Powershell script action or Python Script action.

It will generate a new Output as a Output.

import pandas as pd

# Load the Excel files
df1 = pd.read_excel(r"C:\Users\OneDrive\Desktop\Power Automate Desktop\Practice\VLOOKUP\EMP DATA.xlsx")
df2 = pd.read_excel(r"C:\Users\Desktop\Power Automate Desktop\Practice\VLOOKUP\EMP.xlsx")

# Define the columns to copy
columns_to_copy = ['ITLT', 'IT SLT', 'Business Unit', 'Department', 'Work Area', 'Office City', 'Email Id', 'Status']

# Iterate over each row in df1
for index, row in df1.iterrows():
    email = row['Email']  # Change to the correct column name if needed
    
    # Find the match in df2
    match = df2[df2['Email Id'] == email]
    
    # If a match is found, update the corresponding columns in df1
    if not match.empty:
        for col in columns_to_copy:
            df1.at[index, col] = match.iloc[0][col]

# Save the updated df1 to a new Excel file
df1.to_excel(r"C:\Users\Desktop\VloopkupOutput.xlsx", index=False)

print("Data transfer complete!")

 

(Note:- if you got your solution you can mark as solution and gives kudos)


Thanks & Regards

Vishnu Reddy

Hi @VishnuReddy1997 
I have made few changes and its working as expected. 
Thank you so much!!! 

Hi @Sanket1 ,

 

Great to hear. Please except my reply as a solution so it will help others in the future.

 

Regards,

Vishnu Reddy

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (429)