Paste values under certain number of rows with worksheet array loop

  • Hello,


    I am trying to have the macro loop through the worksheets, copy data, paste to another tab, under the last set of data each time. The issue is that when I use the below, the column of data that was originally pasted in does not go all the way to the bottom of the rows where there is data in other columns.

    Code
    .Range("D" & Rows.Count).End(xlUp).Offset(1)


    For example in the picture you can see there are blanks in column D but the data for the Quarters to the right are populated. (These Quarter columns are not continuous data either/have blanks so using the above code in a similar fashion won't work I don't think?)


    [ATTACH=CONFIG]57541[/ATTACH]


    The only way I can think of is to run through the first work sheet as listed below, then the other worksheets with something like:

    Code
    Worksheets("Sup_Data").Range("D" & intgroup).Offset(1).PasteSpecial (xlPasteValues)


    But this only results in pasting over the same cells each time. I'd need each subsequent sheet to be intgroup *2 or something?





    Any help would be greatly appreciated!


    Thank you!

  • Re: Paste values under certain number of rows with worksheet array loop


    you can find the last row also with

    Code
    LR = ActiveSheet.UsedRange.SpecialCells(xlLastCell, xlNumbers).Row
  • Re: Paste values under certain number of rows with worksheet array loop


    Hi, patel,


    could you please elaborate on

    Code
    SpecialCells(xlLastCell, xlNumbers)


    Ciao,
    Holger

  • Re: Paste values under certain number of rows with worksheet array loop


    What do I dim LR as? an integer? It doesn't work if I dim it as a Range...


    So are you proposing that my updated code should be:



  • Re: Paste values under certain number of rows with worksheet array loop


    LR is a row number, the can be integer or long, did you solve ?

  • Re: Paste values under certain number of rows with worksheet array loop


    Quote from patel;692117

    LR is a row number, the can be integer or long, did you solve ?


    I was not able to solve :(
    I tried to Dim as both an integer and Long with the code I just posted above.
    The result is that when it loops through the 2nd worksheet it just pastes over the previous pasted values.
    And when I hover over LR in the code it says "LR = 1" So it just keeps pasting in row 2.

  • Re: Paste values under certain number of rows with worksheet array loop


    Here's what I ended up using that worked!



Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!