+ Reply to Thread
Results 1 to 5 of 5

VBA to find data in Sheet 2 copy and paste back in Sheet 1

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    VBA to find data in Sheet 2 copy and paste back in Sheet 1

    Hello,

    I have sheet1 and sheet2.

    1) There is list of names in Column A of Sheet1
    2) There is data of employee and their prod value in Sheet2. Employee name in Column A and prod value in Column G
    3) I need VBA which will pick up the Column A from sheet1, find the match in Sheet 2 and copy the prod value in Sheet 1 Column K.

    Please assist.

    Thanks,
    Shiva
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  2. #2
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA to find data in Sheet 2 copy and paste back in Sheet 1

    Hi Shiva,

    Please see the code below and attachment example as well.
    Your feedback will be greatly appreciated!

    Sub FindValueOneSheetToAnother()
        Dim i, lastRow As Integer
        Dim productName As String
        
        lastRow = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
        For i = 2 To lastRow
            productName = lookupFunction(Sheets("Sheet1").Cells(i, 1).Value, Sheets("Sheet2").Range("A:G"), 7, False)
            Sheets("Sheet1").Cells(i, 11).Value = productName
        Next
    End Sub
    
    Function lookupFunction(lookupValue, rnglookupvalue, colIndex, conValue)
        On Error GoTo ErrorHandler
        lookupFunction = Application.WorksheetFunction.VLookup(lookupValue, rnglookupvalue, colIndex, conValue)
        Exit Function
    ErrorHandler:
        lookupFunction = "Not Found!!!"
        Exit Function
    End Function
    I will post this example on my site feel free to see other excel example as well.

    Thank you,
    Alfonso
    Attached Files Attached Files
    Last edited by fonzie29; 03-07-2014 at 03:53 PM.

  3. #3
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    Re: VBA to find data in Sheet 2 copy and paste back in Sheet 1

    Thanks.. Works like a charm..

    One question though.. If I want to change the Paste value to column L instead of K..

    How to modify your code?

    Thanks
    Last edited by shiva_reshs; 03-10-2014 at 04:05 PM.

  4. #4
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    Re: VBA to find data in Sheet 2 copy and paste back in Sheet 1

    np.. got it..

    Sheets("Dump").Cells(i, 12).Value = productName
    Thanks fonzie29 for your code.

    Regards,
    Shiva

  5. #5
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA to find data in Sheet 2 copy and paste back in Sheet 1

    Hi Shiva,

    columns are referenced on the 2 argument of the cells property, so for instance A = 1, B = 2, L = 12 and so on. From what i see you have figured it out.
    For other excel examples using vba check out my site.

    Could you kindly add a reputation using the bottom left corner link "Add Reputation".

    Thank you very much,
    Fonzie29

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Find Value of First sheet in another and copy related data for that cell value and paste.
    By deepak.sirsale in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-30-2013, 09:26 AM
  2. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  3. Find value in cells in other sheet and the copy the informations back
    By esbenhaugaard in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 07:30 PM
  4. Find Adjacent Data In One Sheet and Copy/Paste Into Other Sheet
    By jaylotheman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2011, 07:19 PM
  5. Find value from sheet 1, cell A1 in sheet(s) 2 (3, 4?), copy, paste row to sheet 8
    By fleeting in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2011, 03:31 PM

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.6.0 RC 1