+ Reply to Thread
Results 1 to 4 of 4

How to improve time on copying last row n times below data + leave last row as formula

  1. #1
    Registered User
    Join Date
    03-05-2018
    Location
    GENEVA, SWITZERLAND
    MS-Off Ver
    10
    Posts
    17

    How to improve time on copying last row n times below data + leave last row as formula

    Hi dear comunity! I am pretty new on the VBA world.

    I am currently trying to achieve something, and i am not sure how to do it.


    I have a worksheet in an excel file that has x rows and y columns (it changes across time). The last row is all formulas (not pure values).

    I am currently trying to:

    1. find last row
    2. copy that row
    3. paste n times below (n is defined before and is never more than 15-30).
    4. Then copy and paste all the data as value LESS last row.

    So far I've done this, but it gives me the impression that with the iteration in i is pretty slow....

    Dim lRow As Long
    Dim i As Integer

    'n is defined above

    For i = 1 To n
    lRow = Ws.Cells(Rows.Count, 1).End(xlUp).Row

    Ws.Range("A" & lRow).EntireRow.Copy Ws.Range("A" & lRow + 1)

    Next i


    Is there a way to do it directly? without iteration? just copy n times? I also didn't find much info on how to keep all the rows as value less last one.

    Could you guys pls help? thanks in advance!
    Last edited by laura.gomper; 02-08-2023 at 08:43 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: How to improve time on copying last row n times below data + leave last row as formula

    try such approach:
    Please Login or Register  to view this content.
    PS. Note how CODE tags improve readability
    Last edited by Kaper; 02-07-2023 at 09:58 AM. Reason: changed range(...).entirerow to shorter and i think quicker rows(...)
    Best Regards,

    Kaper

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: How to improve time on copying last row n times below data + leave last row as formula

    Quote Originally Posted by laura.gomper View Post
    ... without iteration ... just copy n times ...
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-05-2018
    Location
    GENEVA, SWITZERLAND
    MS-Off Ver
    10
    Posts
    17

    Re: How to improve time on copying last row n times below data + leave last row as formula

    Thanks to both, both worked like a charm!!

+ 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. Formula to return leave data between two dates.
    By AngelaHughes3233 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-19-2021, 02:43 AM
  2. [SOLVED] Formula for counting # of times 2 sets of data shows up
    By Statz in forum Excel General
    Replies: 3
    Last Post: 10-31-2016, 11:17 AM
  3. [SOLVED] If cell has a formula, copy text to TextBox and leave formula unchanged in cell
    By yachrishere in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2016, 06:26 PM
  4. [SOLVED] How To Not Copy Table - If Filters Leave No Data?
    By mrazexcel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-23-2016, 10:32 PM
  5. [SOLVED] Formula to leave cell Blank until cells of formula have data
    By mbauman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-27-2015, 01:28 PM
  6. [SOLVED] Formula to copy rows of data from one page to another multiple times
    By iamcalledjosh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-13-2013, 05:31 PM
  7. Formula to count the times two columns have data
    By spacec0w in forum Excel General
    Replies: 2
    Last Post: 02-05-2009, 08:49 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