Results 1 to 7 of 7

Loop to find data in a worksheet and copy into a different worksheet.

Threaded View

  1. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Loop to find data in a worksheet and copy into a different worksheet.

    Hi you could use this code to loop through all cells and return the values.
    However i cant for the life of me remember why this does not work.
    Its to do with you having tables.
    if you done away with the tables and all ranges were formatted the same way then this should work.

    your date formats are not the same between customer & price sheet that is also causing a problem.

    Sub ProductPrice()
    Dim ws As Worksheet
    Dim lastrow As Integer
    Dim Pricerng As Range, cell As Range
    
    lastrow = Sheet19.Cells(Rows.Count, 1).End(xlUp).Row
    Set Pricerng = Sheet19.Range("A2:B" & lastrow)
    
    For Each ws In ThisWorkbook.Worksheets
        If InStr(1, ws.Name, "Customer") > 0 Then
            For Each cell In ws.Range("A2:A" & ws.Cells(Rows.Count, 1).End(xlUp).Row)
                cell.Offset(, 2).Value = Application.VLookup(cell.Value, Pricerng, 2, True)
            Next cell
        End If
    Next
    End Sub
    Last edited by Sean Thomas; 10-28-2013 at 01:51 PM. Reason: error in code
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2012, 04:02 AM
  2. Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2012, 02:49 AM
  3. Auto-find and copy data from one worksheet to another
    By dooray in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-12-2012, 02:47 PM
  4. Loop through Worksheet and copy data into a templated worbook.
    By DDmonk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-22-2011, 12:06 PM
  5. Copy Data between sheets with a worksheet loop
    By wjsok85 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2010, 07:51 AM

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