Repeating my code until the last row of data

KNKN9

Board Regular
Joined
Mar 27, 2017
Messages
92
Hi ,

I have the data set

COL ACOL BCOL CCOL DCOL E
ROW1DATADATADATA
ROW2DATADATADATA
ROW3DATADATADATA
ROW4DATADATADATA
ROW5DATADATADATA
ROW6DATADATADATA
ROW7DATADATADATA

<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>
</tbody>


At the moment my code copies the information from row 1. However, I need this to happen for the last row of a spreadsheet. As the last row differs from each spreadsheet.

Can someone help amend my code below so it is able to function for data until the last row ?



Code:
Sub data()


'copying projects
ActiveSheet.Range("A3:L3").Copy
Sheets("Sheet4").Range("N1").End(xlDown).Offset(1, -13).PasteSpecial Paste:=xlPasteValues


With Sheets("sheet1")
    Set rng = .Range(.Cells(1, 15), .Cells(1, .Cells(1, .Columns.Count).End(xlToLeft).Column))
    Set rng1 = .Range(.Cells(2, 15), .Cells(2, .Cells(2, .Columns.Count).End(xlToLeft).Column))
    Set rng_3 = .Range(.Cells(3, 13), .Cells(3, .Cells(3, .Columns.Count).End(xlToLeft).Column))
End With


'copying roles and planned hours


rng.Copy
Sheets("Sheet4").Range("N1").End(xlDown).Offset(0, -1).PasteSpecial xlValues, Transpose:=True
rng1.Copy
Sheets("Sheet4").Range("N1").End(xlDown).Offset(1, 0).PasteSpecial xlValues, Transpose:=True


'copy_actual hours
rng_3.Copy
Sheets("Sheet4").Range("N1").End(xlDown).Offset(-51, 1).PasteSpecial xlValues, Transpose:=True




End Sub

Thanks in advanced.




<colgroup><col><col><col><col><col><col><col span="2"><col><col><col><col><col><col><col></colgroup><tbody></tbody>
 
I am trying to set-up your exact scenario so I can test it, but it is not working, as you have other lines of code that blows things up for me, like this one:
Code:
Sheets("Sheet4").Range("N1").End(xlDown).Offset(-51, 1).PasteSpecial xlValues, Transpose:=True
Because of that Offset command, unless there is data in column N down to at least row 52 at the very start, this line of code will cause errors.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
COL LCOL MCOLNCOL OCOL P
ROW 1project 1Role 1String 1values
ROW 2Role 1String 2values
ROW 3Role 1String 3values
ROW 4Role 1String 4values
ROW 5Role 1String 5values
ROW 6project 2Role 1String 1values
Role 1String 2values
Role 1String 3values
Role 1String 4values
Role 1String 5values

<tbody>
</tbody>


Col N gets pasted first then i need col M to start where col N starts hence the offset 51

<tbody>
</tbody>
 
Last edited:
Upvote 0
I am sorry, I don't think I can help much further. I think that without having a copy of your data to see what you are working with, and without a clear explanation of how you want all this to work, it is extremely difficult to help you.

My intention was to answer your question about how to find the last row of data (which I did). I assumed that the rest of the code was already working properly, and it was just that part you needed help with. But it appears that may not be the case (or at least not with how I am trying to set up the data baased on your replies).

If you do actually have it working the way you want for a set number of rows, then upload a copy of your workbook and provide a link to it, and I will try to download it later and see if I can make your code dynamic.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top