+ Reply to Thread
Results 1 to 6 of 6

Help adapting an existing macro.

Hybrid View

paul1970 Help adapting an existing... 10-10-2008, 07:19 AM
martesoft Sub copy_duplicate() Dim... 10-10-2008, 07:31 AM
royUK Paul, please take more care... 10-10-2008, 08:30 AM
paul1970 Thanks Martesoft but it's not... 10-10-2008, 09:10 AM
royUK Please Edit the Title or I... 10-10-2008, 09:28 AM
paul1970 Sorry, but it's not an easy... 10-10-2008, 09:50 AM
  1. #1
    Registered User
    Join Date
    10-08-2008
    Location
    on the edge of insanity!
    Posts
    3

    Help adapting an existing macro.

    Hi,
    First of all this is a great forum and I can honestly say you've all taught me everything I know about VBA (2 whole days experience!).
    Anyway, I've modified this macro I found on this forum, all it does is compares 2 lists of 6 digit serial numbers and and then tells me which numbers are in list 1 that are not in list 2.
    However, I want to modify it so that it also gives me the numbers in list 2 that are not in list 1 (put into column F). I then need it to cut the matching serial numbers (in columns A and B) from sheet 1 and paste them into sheet 2.

    Can anyone help?

    Here's the code for what I have so far.

    Sub copy_duplicate()
        
        Range("D4:D1000").Select
        Selection.ClearContents
        Range("D4").Select
        
        Dim r As Long
        Dim cr As Long
        r = 4
        cr = 4
        On Error Resume Next
        Do While Sheet1.Cells(r, 1) <> ""
           a = Application.WorksheetFunction.VLookup(Sheet1.Cells(r, 1), Range("B:B"), 1, 0)
           
            If a <> "" Then
                
            Else
                Sheet1.Cells(cr, 4) = Sheet1.Cells(r, 1)
                cr = cr + 1
                
            End If
            a = ""
            r = r + 1
        Loop
    End Sub
    Last edited by paul1970; 10-10-2008 at 04:09 PM.

  2. #2
    Registered User
    Join Date
    10-07-2008
    Location
    Wessex
    Posts
    55
    Sub copy_duplicate()
        Dim r As Long
        Dim cr As Long
        Dim cr2 As Long
        Dim a As Variant
        
        Sheet1.Range("E4:E1000").ClearContents
        Sheet2.Range("F4:F1000").ClearContents
        
        r = 4
        cr = 4
        cr2 = 4
        On Error Resume Next
        Do While Sheet1.Cells(r, 1) <> ""
            a = Application.WorksheetFunction.VLookup(Sheet1.Cells(r, 1), Range("B:B"), 1, 0)
           
            If a = "" Then
            
                Sheet1.Cells(cr, "F") = Sheet1.Cells(r, 1)
                cr = cr + 1
            Else
            
            
                Sheet2.Cells(cr2, "E") = Sheet1.Cells(r, 1)
                cr2 = cr2 + 1
            End If
            
            a = ""
            r = r + 1
        Loop
    End Sub

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Paul, please take more care that your Thread Titles convey a better idea of what you want in future. Read the Forum Rules to see why.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    10-08-2008
    Location
    on the edge of insanity!
    Posts
    3
    Thanks Martesoft but it's not quite what I was after.

    It does copy the duplicate serial numbers across to the second sheet but it doesn't remove them from the first sheet.

    How is this done?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please Edit the Title or I will lock the Thread!

  6. #6
    Registered User
    Join Date
    10-08-2008
    Location
    on the edge of insanity!
    Posts
    3
    Sorry, but it's not an easy question to sum up in a couple of words.
    Am I posting in the wrong section of the forum? If so, can you tell me where I need to post and then please delete this thread.

+ 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. macro to create a macro?
    By jojotherider in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2008, 08:34 PM
  2. Macro for copy/insert into expanding table
    By Soslowgt in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-06-2008, 07:24 PM
  3. How to splitt texts into words? (collecting word and compounds)
    By wali in forum Excel Programming / VBA / Macros
    Replies: 53
    Last Post: 02-03-2008, 04:06 AM
  4. Conditional formatting macro (highlight macro)
    By c991257 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2007, 02:46 PM
  5. Need macro to move down & select next visible row
    By Fartnuckles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2006, 10:02 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