Consulting

Results 1 to 4 of 4

Thread: Solved: Moving rows from one sheet to another using vlookup

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Solved: Moving rows from one sheet to another using vlookup

    Attached is a spreadsheet. The Volume Worksheet sheet (sheet 2) has all the data that will be copied and pasted into the Broker Volume Master spreadsheet table (sheet 1). For example, in the volume worksheet, is there a way to move Row 2 which has broker Angel Oak Capital into the Broker Volume Master Spreadsheet. Basically a way to use a macro that looks up the broker on the volume worksheet, goes into the the drop down in Column A1 of the broker volume master sheet, selects only the correct broker, and inserts that row into the next available row of the table?

    Thanks for the help, you all have really be very helpful!
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    actually i dont need to get that complicated. All i need to do is select all the rows in the volume sheet and have them copy and pasted into the table on the broker volume sheet

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    Broker Volume Master Worksheet - Column A: unique broker names.

    In Volume Worksheet - Column F : repeated broker names (brokers that made multiple transactions, i believe.)

    Broker Volume Master Worksheet - Row 1: 8 column headings, 4 of which are from 24 headings (row1) in Volume Worksheet.

    if you want to copy-paste all data from Volume to Broker Volume Master, no problem (1); if you wish only related columns be copied, no problem (2).

    but if you want stg else, you should be more specific.

    (1)
    [vba]
    Sub CopyAllData()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim LastRow As Long, LastCol As Long

    Set ws1 = Sheets("Volume")
    Set ws2 = Sheets("Broker Volume Master")

    LastRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column

    ws1.Activate
    Range(Cells(1, 1), Cells(LastRow, LastCol)).Copy
    ws2.Range("A1").PasteSpecial xlValues
    Application.CutCopyMode = False

    End Sub
    [/vba]


    (2)
    [vba]
    Sub CopyRelatedCols()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim r As Range, c As Range, rng As Range
    Dim LastRow As Long
    Dim s As String

    Set ws1 = Sheets("Volume")
    Set ws2 = Sheets("Broker Volume Master")

    For Each c In ws2.Range("A1:H1")
    s = c.Value
    Set r = ws1.Cells.Find(what:=s, After:=Range("A1"), LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext)
    If Not r Is Nothing Then
    ws1.Activate
    LastRow = Cells(Rows.Count, r.Column).End(xlUp).Row
    Range(Cells(r.Row, r.Column).Offset(1, 0), Cells(LastRow, r.Column)).Copy Destination:=ws2.Cells(c.Row, c.Column).Offset(1, 0)
    End If
    Next

    End Sub[/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •