+ Reply to Thread
Results 1 to 8 of 8

Thread: Find a record on one excel file based on the value in another file.

  1. #1
    Registered User
    Join Date
    01-22-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Find a record on one excel file based on the value in another file.

    Please can somebody help!!!

    Firstly I am not trying to extract free labour, I have tried my best to resolve this over the last week, searched numerous forums for the answer but to no avail.

    Here goes.... I have two excel files: -

    1st excel file is named 'BPC Form' of which I have a button in the top left of the form named 'Transfer Data'. The form is filled in as a (Part 1 Submission) and when clicked it selects various cells on the form, opens up my 2nd excel file named 'BPC Projects Datas' and copies the data in row format into this 2nd form.

    The 'BPC Form' will at a later date be filled in with additional information known as a (Part 2 Submission). However what I would like is that when the 'Transfer Data' button is clicked this time, it looks at the Archdiocesan Job No named Arch No on the 'BPC Form', opens up the 2nd form 'BPC Projects Datas' and looks for the corresponding/matching Arhdiocesan Job No in column A and pastes the additional infromation into that row.

    I have attached both files so that you can see my coding and that I have tried to make an attempt at this.
    I have indicated in the coding behind the button the point at which I am stuck.

    Kind Regards
    Steve
    Attached Files Attached Files
    Last edited by steve troughton; 02-09-2012 at 03:42 PM. Reason: 1st question now solved

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Find a record on one excel file based on the value in another file.

    Can you specify which data goes in which cells of the 2nd form?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-22-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Find a record on one excel file based on the value in another file.

    Hi Arlette,

    There are several cells requiring data transfer to Sheet 2, however I put in my code two of these cells (listed below also) that could be used as samples for now and then I could add the remaining myself.

    If however it is easier for you to show me how the code works and where I have gone wrong by me giving you all the cell references I am happy to do this also.

    Cell name 'Stage1BuildingCosts' of BPC Form (1st Form), to be copied to Column H of 2nd Form
    Cell name 'TopContractor' of BPC Form (1st Form), to be copied to Column O of 2nd Form

    As explained in my first email, both to be copied to row where Archdiocesan Job No (Column A) of 2nd Form matches - Cell Ref 'Arch No' from BPC Form (1st Form)

    Thank you for replying it is greatly appreciated.
    Please let me know if I have not clearly explained this or you do want all the cell references that require transfer.

    Kind Regards
    Steve

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Find a record on one excel file based on the value in another file.

    I guess you have used several named ranges for these cells and its pretty tedious to actually look up the cell reference. Will it be easier for you to specify the cell reference like A3, C4, etc?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Find a record on one excel file based on the value in another file.

    Have a form that populates using VLOOKUP from the other workbook
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  6. #6
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Find a record on one excel file based on the value in another file.

    I can see a few problems with your code:
    'Stuck from here onwards, please help.....
    
            Application.ScreenUpdating = False
            Set SrcBook = ThisWorkbook
    
            On Error Resume Next
            Set DestBook = Workbooks.Open("C:\Users\stevet\BPC Projects Datas.xlsx")
    
    
            Dim CompareRange As Variant, x As Variant, y As Variant, Seletion As Variant
            ' Set CompareRange equal to the range to which you will
            ' compare the selection.
            Set CompareRange = DestBook.Sheets("Sheet1").Range("A65536").End(xlUp).Row 
    As written, the variable CompareRange will return an integer, not a range.
    This will cause an error when attempting to run the For each y loop below.
    
            Set Selection = SrcBook.Sheets("BPC Form").Range("ArchNo").Value 
    Again, as written, this variable will not return a range, causing the For each x loop to error.
    Also, it is very poor practice to use the name of a VBA function, method or property as a variable name.
    
            ' NOTE: If the compare range is located on another workbook
            ' or worksheet, use the following syntax.
            ' Set CompareRange = Workbooks("Book2"). _
              '   Worksheets("Sheet2").Range("C1:C5")
            '
            ' Loop through each cell in the selection and compare it to
            ' each cell in CompareRange.
            For Each x In Selection
                For Each y In CompareRange
                    If y = x Then
                        DestBook.Worksheets(1).Range("H").Value = SrcBook.Sheets("Stage1BuildingCosts").Range("ArchNo").Value
                        DestBook.Worksheets(1).Range("O").Value = SrcBook.Sheets("TopContractor").Range("ArchNo").Value
                        'More values will need transfering but the above are just 2 samples to use to show what I am trying to do.
                    Next y
                Next x
    
            End If
            'End Sub
    
    
            'End If
    
            'ActiveSheet.Protect Contents:=True
        End Sub
    HTH,
    Rich

  7. #7
    Registered User
    Join Date
    01-22-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Find a record on one excel file based on the value in another file.

    Hi Rich,

    Thank-you so much for your help. Up until Tuesday just gone I was still scratching my head trying to understand where and why my code was falling down.
    Thank-you also to other forum members who offered advice and suggestions.
    I will now mark my question as solved and rate accordingly.

    Another quick question if you don't mind and if you are able to help me with please.

    I have wrote code to insert a pdf file into my worksheet as an attachment......and not so much link, however place it in a cell and resize it.
    I have also wrote code to save my excel file as a pdf file.
    However, is it possible to have code produce the following as I am struggling to put the 2 together and a little more besides: -

    On the click of a button, save the current excel sheet I am working on as a pdf file, open up another workbook and copy or transfer this newly created pdf file into this workbook.
    So not so much after transferring/copying individual cells of data, more want to transfer/copy the whole excel file into a new workbook as a pdf attachement.

    Hope this makes some sort of sense.

    Kind Regards
    Steve

  8. #8
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Find a record on one excel file based on the value in another file.

    Sorry, not much experience in this area. Open a new thread and post your existing code. I'm sure someone will give it a go.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0