+ Reply to Thread
Results 1 to 5 of 5

VBA Comapre, Match & Copy Data

Hybrid View

hobbiton73 VBA Comapre, Match & Copy... 11-19-2013, 03:36 AM
AB33 Re: VBA Comapre, Match & Copy... 11-19-2013, 04:19 AM
hobbiton73 Re: VBA Comapre, Match & Copy... 11-19-2013, 04:47 AM
AB33 Re: VBA Comapre, Match & Copy... 11-19-2013, 05:11 AM
hobbiton73 Re: VBA Comapre, Match & Copy... 11-19-2013, 05:13 AM
  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Comapre, Match & Copy Data

    Hi, I wonder whether someone may be able to help me please.

    With some help along the way, I've put together the following code which compares two lists, and where a match is found, copies the associated data from columns F:H which is this part of the my script
    For ac = 2 To 4
    on the "All Projects" sheet and pastes this information to columns D:F on the "In Flight Projects" sheet.

    Sub AdditionalProjectsListData()
        
        Dim Dic As Object
        Dim Dn As Range
        Dim n As Long
        Dim rng As Range
        
        With Sheets("All Projects")
            Set rng = .Range(.Range("C5"), .Range("C" & Rows.count).End(xlUp))
        End With
        
        Set Dic = CreateObject("scripting.dictionary")
        Dic.CompareMode = vbTextCompare
        For Each Dn In rng
            Set Dic(Dn.Value) = Dn
        Next
        
        With Sheets("In Flight Projects")
            Set rng = .Range(.Range("B5"), .Range("B" & Rows.count).End(xlUp))
        End With
        
        For Each Dn In rng
            If Dic.Exists(Dn.Value) Then
                For ac = 2 To 4
                    If ac > 2 Then Dn.Offset(, ac).NumberFormat = "dd/mm/yyyy"
                    Dn.Offset(, ac) = Dic.Item(Dn.Value).Offset(, ac + 1)
                    Next ac
                End If
            Next Dn
    End Sub
    The code works fine, but I'd now like to change this which is where I'm having difficulty.

    What I'm trying to do is only copy from columns F and H on the "All Projects" sheet and paste this into columns D and F on the "In Flight Projects" sheet.

    I just wondered whether someone could possibly look at this please and offer some guidance on how I may go about achceiving this.

    Many thanks and kind regards

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Comapre, Match & Copy Data

    Sub MG27Oct32am()
    Dim Rng As Range, Dn As Range, n As Long
    Dim Dic As Object
    With Sheets("Projects List")
    Set Rng = .Range(.Range("C5"), .Range("C" & Rows.Count).End(xlUp))
    End With
    Set Dic = CreateObject("scripting.dictionary")
    Dic.CompareMode = vbTextCompare
        For Each Dn In Rng
            Set Dic(Dn.Value) = Dn
        Next
    
    With Sheets("In flight")
        Set Rng = .Range(.Range("B5"), .Range("B" & Rows.Count).End(xlUp))
    End With
    For Each Dn In Rng
        If Dic.exists(Dn.Value) Then
    
                 Dn.Offset(, 2) = Dic.Item(Dn.Value).Offset(, 2 + 1)
                 Dn.Offset(, 4) = Dic.Item(Dn.Value).Offset(, 4 + 1)
                 Dn.Offset(, 4).NumberFormat = "mmm yy"
        End If
    Next Dn
    End Sub

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Comapre, Match & Copy Data

    Hi @AB33, thank you very much for taking the time to reply to my post and for the solutino, which workls beautifully.

    May I ask, if it's not too much trouble, if you could possibly add some very quick notes so that I can understand the code, because I am wanting to increase my VBA knowledge.

    Many thanks and kind regards

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Comapre, Match & Copy Data

    Chris,
    I have amended my own code too, but not commented on it as you may find Mick's code easier to understand.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Comapre, Match & Copy Data

    Hi AB33, thank you very much for takign the time to put this together, it is greatly appreciated.

    All the best and kind regards

+ 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. match data 2 sheets. if match, then copy data from one sheet to another
    By flunzy in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-09-2013, 06:38 AM
  2. File comapre and merge
    By zerodegree in forum Excel General
    Replies: 1
    Last Post: 07-30-2013, 02:23 PM
  3. IP Subnet Comapre and write
    By dammler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2013, 04:00 PM
  4. Using a VLOOKUP to comapre data across 2 worksheets
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 05-22-2012, 09:38 AM
  5. [SOLVED] comapre 2 col.
    By Jimish in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 09-28-2005, 09:05 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