+ Reply to Thread
Results 1 to 9 of 9

Macro to find SKU in column; then copy data in row and paste special (values)

Hybrid View

Starkey Macro to find SKU in column;... 09-12-2012, 12:30 AM
Trebor76 Re: Macro to find SKU in... 09-12-2012, 12:50 AM
Starkey Re: Macro to find SKU in... 09-12-2012, 01:01 AM
Trebor76 Re: Macro to find SKU in... 09-12-2012, 01:10 AM
Starkey Re: Macro to find SKU in... 09-12-2012, 02:06 AM
Trebor76 Re: Macro to find SKU in... 09-12-2012, 07:01 AM
Starkey Re: Macro to find SKU in... 09-12-2012, 10:04 PM
Starkey Re: Macro to find SKU in... 09-12-2012, 10:18 PM
Trebor76 Re: Macro to find SKU in... 09-13-2012, 06:05 AM
  1. #1
    Registered User
    Join Date
    09-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    25

    Macro to find SKU in column; then copy data in row and paste special (values)

    Hi all

    I'm trying to do the following:

    I have a list of SKU's in column D, descriptions in column E and data in Column F and G

    I want to build a macro that finds a SKU that I punch in to a cell (D1), to then search the column of D (2:58) for this SKU, and copy the data from Column G (Which is a vlookup) and 'paste special values' into Column F.

    The SKU in cell D1 will change, which is why it will need to probably index search through the column of D, but I've tried a number of times and simply cannot get it to work.

    Any help would be wonderful

    Starkey
    Last edited by Starkey; 09-12-2012 at 10:06 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Hi Starkey,

    Do you really need a macro as won't this formula in cell F1 do the job?:

    =IFERROR(VLOOKUP(D1,$D$2:$G$58,4,FALSE),"")

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    09-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Hi Robert,

    I think I do need the macro, as there will already be data in column F. When I make changes to Column G (Which flows through from another sheet), I need to then permanently record the change in Column F, hence the copy and paste special values element.

    Cheers,

    Starkey

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Could you please upload a workbook with a before and after scenario (devoid of all sensitive information) and I'll see what I can do.

  5. #5
    Registered User
    Join Date
    09-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Example is attached, thanks Robert.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Hi Starkey,

    Try this:

    Option Explicit
    Sub Macro1()
    
        'http://www.excelforum.com/excel-programming-vba-macros/859746-macro-to-find-sku-in-column-then-copy-data-in-row-and-paste-special-values.html?p=2928721
    
        Dim wstSheet1 As Worksheet, _
            wstSheet2 As Worksheet
        Dim rngFoundCell As Range
        Dim lngMatchRow1 As Long, _
            lngMatchRow2 As Long
        
        Application.ScreenUpdating = False
        
        Set wstSheet1 = Sheets("Before")
        Set wstSheet2 = Sheets("Data")
        
        If Len(wstSheet1.Range("C2")) = 0 Then
            MsgBox "There is no entry in cell C2 in sheet """ & wstSheet1.Name & """ to search on." & vbNewLine & "Enter one and try again.", vbExclamation, "My Data Match Editor"
            Exit Sub
        End If
        
        Set rngFoundCell = wstSheet1.Range("B5:B" & wstSheet1.Cells(Rows.Count, "B").End(xlUp).Row).Find(What:=wstSheet1.Range("C2").Value)
                                                                
        If Not rngFoundCell Is Nothing Then
            lngMatchRow1 = rngFoundCell.Row
            Set rngFoundCell = Nothing
        Else
            MsgBox "There is no matching entry for """ & wstSheet1.Range("C2") & """ in Col. B of sheet """ & wstSheet1.Name & """.", vbInformation, "My Data Match Editor"
            Set wstSheet1 = Nothing: Set wstSheet2 = Nothing: Set rngFoundCell = Nothing
            Exit Sub
        End If
        
        Set rngFoundCell = wstSheet2.Range("B5:B" & wstSheet2.Cells(Rows.Count, "B").End(xlUp).Row).Find(What:=wstSheet1.Range("C2").Value)
        
        If Not rngFoundCell Is Nothing Then
            lngMatchRow2 = rngFoundCell.Row
            Set rngFoundCell = Nothing
        Else
            MsgBox "There is no matching entry for """ & wstSheet1.Range("C2") & """ in Col. B of sheet """ & wstSheet2.Name & """.", vbInformation, "My Data Match Editor"
            Set wstSheet1 = Nothing: Set wstSheet2 = Nothing: Set rngFoundCell = Nothing
            Exit Sub
        End If
        
        wstSheet1.Range("D" & lngMatchRow1 & ":G" & lngMatchRow1).Value = wstSheet2.Range("D" & lngMatchRow2 & ":G" & lngMatchRow2).Value
        
        Application.ScreenUpdating = True
        
        MsgBox "The matching data from tab """ & wstSheet2.Name & """ has now been imported to sheet """ & wstSheet1.Name & """.", vbInformation, "My Data Match Editor"
        
        Set wstSheet1 = Nothing: Set wstSheet2 = Nothing
    
    End Sub
    Regards,

    Robert

  7. #7
    Registered User
    Join Date
    09-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Hi Robert!

    Thank you so much. That works exactly the way I want it to. The trick is now incorporating it into my spreadsheet, but I'm sure that will be fairly easy

    Many thanks!

    Starkey

  8. #8
    Registered User
    Join Date
    09-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    EDIT

    Hi Rob, no matter. I worked through your code and discovered how to adjust it accordingly.

    Thank you so much again, this will be really helpful!

    Starkey

    ---

    Hi Robert,

    Sorry if I'm pushing my luck here, but is it also possible to pull the data from just the 'Before' sheet? In essence, the 'Data' tab is pulling from a number of different sheets in my spreadsheet, so that's not a viable option ongoing.

    Cheers,

    Starkey
    Last edited by Starkey; 09-12-2012 at 10:30 PM.

  9. #9
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro to find SKU in column; then copy data in row and paste special (values)

    Hi Starkey,

    I'm glad to have helped and thanks for marking the thread as solved (and for adding to my reputation )

    Kind regards,

    Robert

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