+ Reply to Thread
Results 1 to 9 of 9

How to Create Macro to Search, Copy, & Paste?

Hybrid View

  1. #1
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to Create Macro to Search, Copy, & Paste?

    Try this:
    Sub foo()
        Dim lRow As Long, lEndRow As Long, lPasteRow As Long, lPasteCol As Long
        Dim wsSrc As Worksheet, wsTgt As Worksheet, c As Range, v As Variant
    
        Set wsSrc = Worksheets("Sheet2")
        Set wsTgt = Worksheets("Sheet1")
    
        lPasteRow = wsTgt.Cells(Rows.Count, 1).End(xlUp).Row
        With wsSrc
            lEndRow = .Cells(Rows.Count, 1).End(xlUp).Row
            For lRow = 1 To lEndRow
                If .Cells(lRow, 1).Value = "Name" Then lPasteRow = lPasteRow + 1
                v = .Cells(lRow, 1).Value
                Set c = wsTgt.Range("1:1").Find(v)
                If Not c Is Nothing And Not v = "" Then
                    wsTgt.Cells(lPasteRow, c.Column).Value = .Cells(lRow + 1, 1).Value
                End If
            Next lRow
        End With
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  2. #2
    Registered User
    Join Date
    11-17-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: How to Create Macro to Search, Copy, & Paste?

    Wow, Fantastic mind blowing & unbelievable .It's working fine.


    Thanks a ton, Thanks Thanks Thanks

  3. #3
    Registered User
    Join Date
    11-17-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: How to Create Macro to Search, Copy, & Paste?

    Hi ,


    I am getting few technical errors, especially company name is not copied properly .

    Herewith attached are the examples, can you please fix this.

    Regards,
    Hari
    Attached Files Attached Files

+ 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. [SOLVED] Vba/Macro Search Rows for value and copy/paste accordingly
    By Aquabat in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-21-2013, 02:56 PM
  2. [SOLVED] Search, copy & paste Macro
    By Keixm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2012, 12:11 PM
  3. Search, Copy Paste Macro
    By crazyAMP in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 11-17-2011, 04:47 PM
  4. vba macro - search ID, copy, paste
    By sgp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 07:00 AM
  5. Search, copy and paste macro.
    By Shin278 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2011, 07:42 AM

Tags for this Thread

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