+ Reply to Thread
Results 1 to 4 of 4

Macro Help - Match Copy & Paste

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro Help - Match Copy & Paste

    Quote Originally Posted by davesexcel View Post
    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.


    Keep it simple!
    Doing this will ensure you get the result you need!
    Yes here it is.. thanks by the way
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-03-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro Help - Match Copy & Paste

    This code works for right columns, but i want for left columns data

    Sub MatchAndCopy2()
           
        Dim i As Long, k As Long, n As Variant, rSource As Range, rMatch As Range, rng As Range
        Dim s As String, t As String
        
        Application.ScreenUpdating = False
         
        s = InputBox("Please enter the File Name")
        t = InputBox("Please enter the Start Range")
         
        With Workbooks(s).Sheets("1st WB Sheet1")
            Set rSource = .Range(t, .Range(t).End(xlDown))
        End With
        
        With Workbooks(s).Sheets("2nd WB Sheet1")
            Set rMatch = .Range("A2", .Range("A2").End(xlDown))
            '.Columns("U:X").Clear
        End With
         
        For Each rng In rMatch
            'rng.Interior.ColorIndex = 0
            n = Application.Match(rng.Value, rSource, 0)
            If IsNumeric(n) Then
                With rng.Resize(, 4)
                    .Value = rSource.Rows(n).Resize(, 4).Value
                    '.Interior.ColorIndex = 35
                End With
                 ' Uncomment these two lines if you want copied to Sheet3 also
                 'k = k + 1
                 'rSource.Rows(n).Resize(, 5).Cut Sheets("Sheet3").Rows(k)
            Else
                'rng.Interior.ColorIndex = 3
            End If
            'i = i + 1
        Next rng
         
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
        Windows(s).Activate

+ 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