Results 1 to 3 of 3

How to Copy a full Row from a Worksheet to the front of a column

Threaded View

  1. #1
    Registered User
    Join Date
    12-05-2019
    Location
    Lisbon
    MS-Off Ver
    365 ProPlus
    Posts
    5

    How to Copy a full Row from a Worksheet to the front of a column

    Hi Gurus

    I'm working on a VBA code that organizes and matchs data from two diferent excels, and produces a new document with the data.

    To Match the data, I want to keep the full row of document A, and in front of the last column of this document I Want to insert the match from document B.

    I've managed to copy the data from both documents, to diferent sheets of the new document and i can make the data match in "Sheet1", but i cant copy to the place i want.

    I've Tried something like


    Do While Workbooks(NewWb.Name).Worksheets("Sheet1").Cells(i, 2).Value <> ""
    
        str1 = Workbooks(NewWb.Name).Worksheets("Sheet1").Cells(i, 2).Value
        
        Do While Workbooks(NewWb.Name).Worksheets("Sheet2").Cells(rb, cb).Value <> ""
        
            str2 = Workbooks(NewWb.Name).Worksheets("Sheet2").Cells(rb, cb).Value
        
                If InStr(str2, str1) > 0 Then
                
                    Workbooks(NewWb.Name).Worksheets("Sheet2").Rows(rb).EntireRow.Cut Workbooks(NewWb.Name).Worksheets("Sheet1").Cells(rb, column).EntireRow
                    
                Else
                End If
                
            rb = rb + 1
        Loop
        
        rb = user_row
        
        i = i + 1
    Loop
    The Thing is, instead of pasting the row in front of the pretended column, it substitutes the row from "Sheet1" with the result from the "Sheet2". I think its because I'm using the "EntireRow" Function on this line

    Workbooks(NewWb.Name).Worksheets("Sheet2").Rows(rb).EntireRow.Cut Workbooks(NewWb.Name).Worksheets("Sheet1").Cells(rb, column).EntireRow
    I've tried using range, but nothing seems to work.



    Below an example of the expected result

    Sheet1

    Product | Component | Description
    A | 10 | Thank
    B | 20 | You


    Sheet2

    Product | Price | Time to produce
    A | 10 | 10h
    B | 20 | 20h


    Expected Result

    Product | Component | Description | Product | Price | Time to produce
    A | 10 | Thank | A | 10 | 10h
    B | 20 | You | B | 20 | 20h


    Please help!

    Best regards and Thanks in Advance
    Last edited by lquesado; 12-17-2019 at 09:33 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do I add a set of numbers in front of a full column?
    By petstoreguy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-30-2015, 09:03 PM
  2. [SOLVED] copy data from cells in a column on one worksheet to a single cell in another worksheet
    By jpsnickers in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2013, 07:02 PM
  3. Macro to delete column in front of yellow highlighted column
    By Getsuko Teng in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2012, 02:30 PM
  4. extraneous time in front of front of Gantt Chart
    By carsto in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-29-2011, 10:05 AM
  5. Need to copy text from full "A" column to "A" column on new sheet....
    By Stonesifer in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-15-2011, 02:50 PM
  6. Replies: 3
    Last Post: 06-17-2008, 08:57 PM
  7. [SOLVED] Reference to ActiveX control on worksheet requires full worksheet name
    By Ian Ripsher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2005, 12:05 PM

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