Consulting

Results 1 to 5 of 5

Thread: Solved: Copy after the last line of data

  1. #1
    VBAX Tutor joelle's Avatar
    Joined
    Apr 2005
    Location
    Sunnyvale, CA
    Posts
    204
    Location

    Solved: Copy after the last line of data

    Dear Experts,

    Its late Friday afternoon and my work is still up to my neck ... and I so
    hope someone could help me with a vb module to tailor this roadblock:

    I have 2 worksheets called "sheetA" and "sheetB" and I would like
    to include some codes (that I dont know how to write) as part of
    an existing macro of mine so that this macro copies lines 10-20 of
    sheetA and paste them below the last line of sheetB that has data.

    SheetB always has data but I dont know where the last with data will be because data depends on how long the price quote takes and the data is generated by another macro.

    Many many thanks in advance,

    Nee

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Night time in Jersey and it's FREEZING!

    Here's a little something to get you going
    [VBA] Option Explicit
    Sub CopyPaste()
    Dim iLastRowB As Long
    iLastRowB = Sheets("sheetB").Cells(Rows.Count, "A").End(xlUp).Row + 1
    Sheets("sheetA").Range("10:20").Copy
    Sheets("sheetB").Range("A" & iLastRowB).PasteSpecial xlAll
    Application.CutCopyMode = False
    End Sub

    [/VBA]
    HTH




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Sorry, forgot you said that you didn't know when the last row of sheetB was...so I fixed it up a bit

    Just make sure that any data in sheetB has something (in the corresponding column) in the first row.

    [VBA] Option Explicit
    Sub CopyPaste()
    Application.ScreenUpdating = False
    Dim iLastRowB As Long
    Dim iLastCol As Long
    Dim ActiveRows As Long
    Dim MostRows As Long
    Dim iCol As Long
    iLastCol = Sheets("sheetB").Cells(1, Columns.Count).End(xlToLeft).Column
    MostRows = 0
    For iCol = 1 To iLastCol
    ActiveRows = Sheets("sheetB").Cells(Rows.Count, iCol).End(xlUp).Row
    If ActiveRows > MostRows Then MostRows = ActiveRows
    Next iCol
    Sheets("sheetA").Range("10:20").Copy
    Sheets("sheetB").Range("A" & MostRows).PasteSpecial xlAll
    Application.CutCopyMode = False
    Sheets("sheetB").Range("A" & MostRows).Select
    Application.ScreenUpdating = True
    End Sub
    [/VBA] There, that should do it




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  4. #4
    VBAX Tutor joelle's Avatar
    Joined
    Apr 2005
    Location
    Sunnyvale, CA
    Posts
    204
    Location
    Joe -- Thanks so much!!

    Its late and cold there and you would not mind writing codes!
    They work and I'm so appreciative.

    Btw, it is gorgeous here now its 4pm !!

    Have a great night there -- keep warm!!

    Nee

  5. #5
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by Nee
    Joe -- Thanks so much!!

    Its late and cold there and you would not mind writing codes!
    They work and I'm so appreciative.

    Btw, it is gorgeous here now its 4pm !!

    Have a great night there -- keep warm!!

    Nee
    You're welcome

    And I'll be keeping warm when I move to Florida! WHOOOO!!!!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

Posting Permissions

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