VBA Copy data

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
HI,

I have 2 pages in a spreadsheet. I would like to automate copying data from one to another.

Firstly, I need some code to add to an existing button that will copy the task list from A6:Azzz (could be A6:A20 could be A6:A4544) and paste this onto a new page in A2:Azzz

I then need some code that will copy the report date and actual %ages from the progress report to this new page. This will be done weekly so evetually this new sheet will show where we were upto on each report date. This data could be pasted into the next available column, if the reports are done in date order. Sometimes these will be done retrospectively so I need to ensure that it will paste into the correct place.

Thanks in advance.
Derby Uni PR.xls
ABCDEF
1SiteNameMarkeatonCampus-UniversiyofDerby
2ProjectNumber RelatedProgrammeRevisionE32012 ConstructionProgrammeRev1st
3ReportDateAverageActual
412/12/20035%11%
5ActivityStartDateFinishDateScheduleActualSlippage (Days)
6ErectHoardingtoSiteBoundary24/11/200308:0026/11/200317:00100%100%0
7Locate&MarkExistingServices24/11/200308:0026/11/200317:00100%100%0
8ErectionofExternalScaffold08/12/200308:0019/12/200317:0050%100%-5
9SetupSiteCompound05/01/200408:0007/01/200417:000%100%-3
10AsbestosRemovaltoRearBays20/11/200308:0005/12/200317:00100%100%0
11AsbestosRemovaltoFrontBays08/12/200308:0028/01/200417:0013%100%-33
12ExcavateforNewDrainage08/12/200308:0009/01/200417:0020%100%-20
13LayPipes&ConnecttoExisting07/01/200408:0014/01/200417:000%0%0
14Backfill&MakeGoodGround05/01/200408:0023/01/200417:000%0%0
15StripOutRedundantServices&Sanitaryware08/12/200308:0019/12/200317:0050%100%-5
Progress Report
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Cell A102 in this case. Works fine on all task lists, regardless of size.

The VBA code always selects this smaller range tho.

very strange . . .
 
Upvote 0
What row is returned when you run this?;

Code:
Sub getlastrow()
MsgBox ("Last row in col. A is " & Range("A65536").End(xlUp).Row)
End Sub
 
Upvote 0
and you did run it on the progress report sheet?

try this;

Code:
Sub firstcopy()
Dim mylastrow As Integer
mylastrow = Range("A65536").End(xlUp).Row
Sheets("Progress Report").Range("A6:E" & mylastrow).Copy Sheets("As Built Data").Range("A2")
Sheets("As Built Data").Columns("B:D").Delete

End Sub
 
Upvote 0
Sorry Jimboy, I was running this from a command button on another sheet and assumed it would still work. It was taking the last row from the sheet containing the button.

On the 2nd part of the code, it copies the data OK to the As Built Page, but I get d runtime error 1004 on . .

Sheets("As Built data").Range(Cells(2, mycolumn), Cells(5000, mycolumn)).NumberFormat = "0.00%"

Application or Object-defined error

It pastes the data OK, just doesn't format to %

Any ideas ?
 
Upvote 0
Sorry for the delay Jim,

The 2 mycolumn fields show as 2 and 3 respecively when it debugs

Also, its not pasting in all the values, its missing a few at random ? It should paste data into A2:A191, A53,54,55,60,66 and 87 are empty ? I have checked the source data and formats are exactly the same throughout.


Cheers
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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