+ Reply to Thread
Results 1 to 5 of 5

copy variable range from one sheet to top of another, rather than bottom.

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    11

    copy variable range from one sheet to top of another, rather than bottom.

    I'm using the following code, this works great as it picks data up from the Cmonth sheet and makes a copy of this on the archive sheet.
    It currently copies rows with an entry in and places it on the last blank row of the archive sheet.

    Normally this would be sorted to put the newest copied data to the top.
    However i'm being told that there is a need to run this once a month for a year.

    The range to be copied each month could be from 25 to 45 rows. That would mean to have the newest copied data at the top would mean potentially sorting over 500 rows.

    Is there a way to modify the macro below to place the copied range at the top thus removing the need to sort each month.

    I've searched and tried to mod for two days now with no success. If anyone can point me in the wright direction please do!

    Please Login or Register  to view this content.
    Many thanks for taking the time to read the above.

  2. #2
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: copy variable range from one sheet to top of another, rather than bottom.

    Can you attach a sample workbook? What you will need to do is calculate the number of rows of data in Cmonth, insert that many rows at the top of Archive which whould push all data down, and then copy the rows from Cmonth to Archive.

    You can use code similar to this:

    Please Login or Register  to view this content.
    on the Archive sheet where X equals the number of rows of data in Cmonth that you want to copy over.
    Last edited by g8r777; 10-16-2012 at 02:45 PM.

  3. #3
    Registered User
    Join Date
    09-07-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: copy variable range from one sheet to top of another, rather than bottom.

    Attached is a sample file.

    To test i've been manually changing the date in cell D10 on the Cmonth sheet.
    Click on Archive to run the macro.

    Many thanks
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-07-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: copy variable range from one sheet to top of another, rather than bottom.

    Tried calculating the number of rows which works but when i add this into the macro above i get

    Object doesn't support this property or method

    any ideas?

  5. #5
    Registered User
    Join Date
    09-07-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: copy variable range from one sheet to top of another, rather than bottom.

    I've got the following macros in the attached file


    PHP Code: 
    Sub Count_rows_and_insert()

    Dim i As Integer
    endrow 
    Cells(ActiveSheet.UsedRange.Rows.Count 1ActiveCell.Column).End(xlUp).Row
    Sheets
    ("sheet2").Select
    For 1 To endrow
    Rows
    ("2:2").Select
    Selection
    .Insert shift:=xlDowncopyorigin:=xlFormatFromLeftOrAbove
    Next i
    End Sub 
    This worked once but now inserts one line when run again


    PHP Code: 
    Sub Select_Copy_Paste()
    With ActiveSheet
    .Range("C7", .Cells.SpecialCells(xlCellTypeLastCell)).Select
    End With
    Selection
    .Copy
    Sheets
    ("Sheet2").Select
    Range
    ("C3").Select
    ActiveSheet
    .Paste
    Columns
    .AutoFit
    End Sub 
    The one above again worked once but now only copies 5 rows.

    What i'd like to be able to do is combine bothe macros to do the following
    * count the number of used rows on sheet1
    * insert the number of rows on sheet2
    * select the used range on sheet1 and copy it to sheet2 where the first line was inserted.

    Can anyone please point me in the right direction/help.

    Many thanks
    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)

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