SOLVED
Home

Copy specific data from one workbook to another

%3CLINGO-SUB%20id%3D%22lingo-sub-889977%22%20slang%3D%22en-US%22%3ECopy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-889977%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3ECan%20anyone%20kindly%20offer%20some%20advice%20on%20the%20following%3F......%3CBR%20%2F%3EI%20have%20two%20reports%20with%20different%20data%2C%20one%20for%20members%20and%20one%20for%20those%20who%20have%20used%20our%20services%20(both%20have%20the%20name%20column).%3CBR%20%2F%3EWhat%20I%20need%20is%20for%20the%20services%20report%20to%20show%20me%20all%20the%20data%20it%20currently%20lists%20plus%20which%20clients%20are%20members%20and%20what%20type%20of%20membership%20they%20have%20(which%20is%20on%20the%20membership%20report).%3CBR%20%2F%3EUnfortunately%20our%20database%20is%20not%20clever%20enough%20to%20run%20this%20search%20and%20pull%20off%20the%20data%20in%20one%2C%20so%20I%20wonder%20if%20i%20can%20do%20this%20within%20excel%3F%20Vlookup%3F%3CBR%20%2F%3EMany%20thanks%3CBR%20%2F%3EK%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-889977%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20-%20formulas%20data%20worksheet%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%202010%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890435%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890435%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F419117%22%20target%3D%22_blank%22%3E%40Kerrie1383%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20is%20hard%20to%20suggest%20any%20solution%20without%20looking%20at%20the%20layout%20of%20your%20data%20in%20the%20reports.%3C%2FP%3E%3CP%3EWhy%20not%20upload%20the%20sample%20file%20and%20mock%20up%20the%20desired%20output%20in%20another%20sheet%20manually%20to%20show%20us%20the%20end%20result%20you%20are%20trying%20to%20achieve%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890823%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890823%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20please%20see%20below.%3C%2FP%3E%3CP%3EThe%20membership%20report%20%26amp%3B%20service%20report%20are%20both%20in%20separate%20workbooks.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20744px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135260i2689B8E4BD46F7DD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Sample%20reports.jpg%22%20title%3D%22Sample%20reports.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890853%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890853%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F419117%22%20target%3D%22_blank%22%3E%40Kerrie1383%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInstead%20of%20posting%20the%20image%20of%20the%20data%2C%20please%20upload%20the%20Excel%20Workbooks.%3C%2FP%3E%3CP%3EClick%20on%20the%20paper%20clip%20icon%20to%20open%20the%20upload%20window%20and%20upload%20the%20files.%20Refer%20to%20the%20following%20image.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20785px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135263i523236553221B50D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Upload%20File.jpg%22%20title%3D%22Upload%20File.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBtw%20are%20you%20comfortable%20with%20the%20Macro%20Solution%3F%20And%20what%20Excel%20version%20you%20are%20using%2C%20Excel%202010%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890885%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890885%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20I%20have%20attached%20the%20sample%20files%20as%20requested.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20have%20some%20basic%20knowledge%20of%20Macro%20but%20i%20have%20never%20used%20this.%20I%20am%20currently%20using%20excel%202010.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKerrie%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-890977%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-890977%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F419117%22%20target%3D%22_blank%22%3E%40Kerrie1383%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20find%20the%20attached%20with%20the%20code%20on%20Module1%20and%20a%20button%20called%20%22Generate%20Combined%20Membership%20Report%22%20on%20Combined%20Report%20Sheet%20to%20run%20the%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20will%20open%20the%20file%20picker%20dialog%20box%20for%20you%20to%20pick%20the%20Membership%20Report%20first%20and%20then%20Service%20Report%2C%20once%20you%20pick%20both%20the%20files%2C%20the%20code%20will%20generate%20the%20combined%20report%20on%20the%20Combined%20Report%20Sheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%20on%20Module1%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPublic%20Sub%20ExtractMembershipInfo()%0ADim%20wbCombined%20%20%20%20%20%20As%20Workbook%0ADim%20wbMembership%20%20%20%20As%20Workbook%0ADim%20wbService%20%20%20%20%20%20%20As%20Workbook%0ADim%20wsCombined%20%20%20%20%20%20As%20Worksheet%0ADim%20wsMember%20%20%20%20%20%20%20%20As%20Worksheet%0ADim%20wsService%20%20%20%20%20%20%20As%20Worksheet%0ADim%20strFilePath%20%20%20%20%20As%20String%0ADim%20x%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Variant%0ADim%20y()%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Variant%0ADim%20dict%20%20%20%20%20%20%20%20%20%20%20%20As%20Object%0ADim%20i%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Long%0A%0AApplication.ScreenUpdating%20%3D%20False%0A%0ASet%20wbCombined%20%3D%20ThisWorkbook%0ASet%20wsCombined%20%3D%20wbCombined.Worksheets(%22Combined%20Report%22)%0A%0AWith%20Application.FileDialog(msoFileDialogFilePicker)%0A%20%20%20%20.Title%20%3D%20%22Select%20Membership%20Report%20File!%22%0A%20%20%20%20.AllowMultiSelect%20%3D%20False%0A%20%20%20%20.ButtonName%20%3D%20%22Open%20Membership%20Report%22%0A%20%20%20%20.Filters.Clear%0A%20%20%20%20.Filters.Add%20%22Excel%20Files%22%2C%20%22*.xlsx%22%0A%20%20%20%20If%20.Show%20%3D%20-1%20Then%0A%20%20%20%20%20%20%20%20strFilePath%20%3D%20.SelectedItems(1)%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20MsgBox%20%22You%20didn't%20select%20any%20Membership%20Report.%22%2C%20vbExclamation%0A%20%20%20%20%20%20%20%20End%0A%20%20%20%20End%20If%0AEnd%20With%0A%0ASet%20wbMembership%20%3D%20Workbooks.Open(strFilePath)%0ASet%20wsMember%20%3D%20wbMembership.Worksheets(1)%0A%0AWith%20Application.FileDialog(msoFileDialogFilePicker)%0A%20%20%20%20.Title%20%3D%20%22Select%20Service%20Report%20File!%22%0A%20%20%20%20.AllowMultiSelect%20%3D%20False%0A%20%20%20%20.ButtonName%20%3D%20%22Open%20Service%20Report%22%0A%20%20%20%20.Filters.Clear%0A%20%20%20%20.Filters.Add%20%22Excel%20Files%22%2C%20%22*.xlsx%22%0A%20%20%20%20If%20.Show%20%3D%20-1%20Then%0A%20%20%20%20%20%20%20%20strFilePath%20%3D%20.SelectedItems(1)%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20MsgBox%20%22You%20didn't%20select%20any%20Service%20Report.%22%2C%20vbExclamation%0A%20%20%20%20%20%20%20%20End%0A%20%20%20%20End%20If%0AEnd%20With%0A%0ASet%20wbService%20%3D%20Workbooks.Open(strFilePath)%0ASet%20wsService%20%3D%20wbService.Worksheets(1)%0A%0ASet%20dict%20%3D%20CreateObject(%22Scripting.Dictionary%22)%0A%0Ax%20%3D%20wsMember.Range(%22A1%22).CurrentRegion.Value%0A%0AFor%20i%20%3D%202%20To%20UBound(x%2C%201)%0A%20%20%20%20dict.Item(x(i%2C%201))%20%3D%20x(i%2C%202)%20%26amp%3B%20%22_%22%20%26amp%3B%20x(i%2C%203)%0ANext%20i%0A%0AwbMembership.Close%20False%0A%0AwsCombined.Cells.Clear%0A%0AwsService.Range(%22A1%22).CurrentRegion.Copy%20wsCombined.Range(%22A1%22)%0A%0AwbService.Close%20False%0A%0Ax%20%3D%20wsCombined.Range(%22A1%22).CurrentRegion.Value%0AReDim%20y(1%20To%20UBound(x%2C%201)%2C%201%20To%202)%0A%0AwsCombined.Cells(1%2C%20UBound(x%2C%202)%20%2B%201)%20%3D%20%22Membership%20Type%22%0AwsCombined.Cells(1%2C%20UBound(x%2C%202)%20%2B%202)%20%3D%20%22Membership%20Status%22%0A%0AFor%20i%20%3D%202%20To%20UBound(x%2C%201)%0A%20%20%20%20If%20dict.exists(x(i%2C%201))%20Then%0A%20%20%20%20%20%20%20%20y(i%20-%201%2C%201)%20%3D%20Split(dict(x(i%2C%201))%2C%20%22_%22)(0)%0A%20%20%20%20%20%20%20%20y(i%20-%201%2C%202)%20%3D%20Split(dict.Item(x(i%2C%201))%2C%20%22_%22)(1)%0A%20%20%20%20End%20If%0ANext%20i%0A%0AwsCombined.Cells(2%2C%20UBound(x%2C%202)%20%2B%201).Resize(UBound(x%2C%201)%2C%202).Value%20%3D%20y%0A%0AWith%20wsCombined.Range(%22A1%22).CurrentRegion%0A%20%20%20%20.Rows(1).Font.Bold%20%3D%20True%0A%20%20%20%20.Rows(1).Font.Size%20%3D%2013%0A%20%20%20%20.Columns.AutoFit%0A%20%20%20%20.Borders.Color%20%3D%20vbBlack%0AEnd%20With%0A%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-891141%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-891141%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOMG%20this%20is%20amazing%2C%20it%20worked%20on%20the%20sample%20sheets%20but%20not%20on%20the%20original%20reports%2C%20I%20assume%20this%20is%20because%20the%20samples%20did%20not%20include%20all%20data%20as%20per%20the%20original%20report.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20did%20however%20match%20the%20fields%20and%20it%20seemed%20worked...%20so%20I%26nbsp%3B%20have%20just%20sort%20the%20list%20ascending%20by%20name%20and%20copy%20and%20paste%20on%20to%20the%20original%20report.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20your%20help%2C%20I%20really%20appreciate%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKindest%20regards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EK%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-891165%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20specific%20data%20from%20one%20workbook%20to%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-891165%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F419117%22%20target%3D%22_blank%22%3E%40Kerrie1383%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome!%20Glad%20it%20worked%20as%20desired%20and%20you%20were%20able%20to%20tweak%20it%20as%20per%20your%20need.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20take%20a%20minute%20to%20select%20the%20post%20with%20the%20proposed%20solution%20as%20a%20Best%20Response%2FAnswer%20to%20mark%20your%20question%20as%20Solved.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Kerrie1383
New Contributor
Hi,
Can anyone kindly offer some advice on the following?......
I have two reports with different data, one for members and one for those who have used our services (both have the name column).
What I need is for the services report to show me all the data it currently lists plus which clients are members and what type of membership they have (which is on the membership report).
Unfortunately our database is not clever enough to run this search and pull off the data in one, so I wonder if i can do this within excel? Vlookup?
Many thanks
K
7 Replies

@Kerrie1383 

It is hard to suggest any solution without looking at the layout of your data in the reports.

Why not upload the sample file and mock up the desired output in another sheet manually to show us the end result you are trying to achieve?

@Subodh_Tiwari_sktneer

 

Thanks, please see below.

The membership report & service report are both in separate workbooks.

Sample reports.jpg

@Kerrie1383 

Instead of posting the image of the data, please upload the Excel Workbooks.

Click on the paper clip icon to open the upload window and upload the files. Refer to the following image.

Upload File.jpg

 

Btw are you comfortable with the Macro Solution? And what Excel version you are using, Excel 2010?

@Subodh_Tiwari_sktneer 

 

Thanks I have attached the sample files as requested.

 

I am have some basic knowledge of Macro but i have never used this. I am currently using excel 2010.

 

Many thanks

 

Kerrie

Solution

@Kerrie1383 

Please find the attached with the code on Module1 and a button called "Generate Combined Membership Report" on Combined Report Sheet to run the code.

 

The code will open the file picker dialog box for you to pick the Membership Report first and then Service Report, once you pick both the files, the code will generate the combined report on the Combined Report Sheet.

 

Code on Module1:

Public Sub ExtractMembershipInfo()
Dim wbCombined      As Workbook
Dim wbMembership    As Workbook
Dim wbService       As Workbook
Dim wsCombined      As Worksheet
Dim wsMember        As Worksheet
Dim wsService       As Worksheet
Dim strFilePath     As String
Dim x               As Variant
Dim y()             As Variant
Dim dict            As Object
Dim i               As Long

Application.ScreenUpdating = False

Set wbCombined = ThisWorkbook
Set wsCombined = wbCombined.Worksheets("Combined Report")

With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select Membership Report File!"
    .AllowMultiSelect = False
    .ButtonName = "Open Membership Report"
    .Filters.Clear
    .Filters.Add "Excel Files", "*.xlsx"
    If .Show = -1 Then
        strFilePath = .SelectedItems(1)
    Else
        MsgBox "You didn't select any Membership Report.", vbExclamation
        End
    End If
End With

Set wbMembership = Workbooks.Open(strFilePath)
Set wsMember = wbMembership.Worksheets(1)

With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select Service Report File!"
    .AllowMultiSelect = False
    .ButtonName = "Open Service Report"
    .Filters.Clear
    .Filters.Add "Excel Files", "*.xlsx"
    If .Show = -1 Then
        strFilePath = .SelectedItems(1)
    Else
        MsgBox "You didn't select any Service Report.", vbExclamation
        End
    End If
End With

Set wbService = Workbooks.Open(strFilePath)
Set wsService = wbService.Worksheets(1)

Set dict = CreateObject("Scripting.Dictionary")

x = wsMember.Range("A1").CurrentRegion.Value

For i = 2 To UBound(x, 1)
    dict.Item(x(i, 1)) = x(i, 2) & "_" & x(i, 3)
Next i

wbMembership.Close False

wsCombined.Cells.Clear

wsService.Range("A1").CurrentRegion.Copy wsCombined.Range("A1")

wbService.Close False

x = wsCombined.Range("A1").CurrentRegion.Value
ReDim y(1 To UBound(x, 1), 1 To 2)

wsCombined.Cells(1, UBound(x, 2) + 1) = "Membership Type"
wsCombined.Cells(1, UBound(x, 2) + 2) = "Membership Status"

For i = 2 To UBound(x, 1)
    If dict.exists(x(i, 1)) Then
        y(i - 1, 1) = Split(dict(x(i, 1)), "_")(0)
        y(i - 1, 2) = Split(dict.Item(x(i, 1)), "_")(1)
    End If
Next i

wsCombined.Cells(2, UBound(x, 2) + 1).Resize(UBound(x, 1), 2).Value = y

With wsCombined.Range("A1").CurrentRegion
    .Rows(1).Font.Bold = True
    .Rows(1).Font.Size = 13
    .Columns.AutoFit
    .Borders.Color = vbBlack
End With

Application.ScreenUpdating = True
End Sub

 

 

@Subodh_Tiwari_sktneer 

 

OMG this is amazing, it worked on the sample sheets but not on the original reports, I assume this is because the samples did not include all data as per the original report.

 

I did however match the fields and it seemed worked... so I  have just sort the list ascending by name and copy and paste on to the original report.

 

Thank you so much for your help, I really appreciate it.

 

Kindest regards

 

K

@Kerrie1383 

You're welcome! Glad it worked as desired and you were able to tweak it as per your need.

 

Please take a minute to select the post with the proposed solution as a Best Response/Answer to mark your question as Solved.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies