copy and paste between worksheets, problem with code help

geordz

New Member
Joined
Apr 13, 2010
Messages
42
Hi there,
I have the following code which compares a string between two sheets. First sheet is 'data', second is 'saw'. I'm trying to copy an array of numbers (energy consumption for each hour of the day) based on machine ID and date (hence the compare string). Can someone help modify it so it will copy the array of 24 number, not just the first number?

I have a few worksheets 'saw', drill, lathe. So I am using ActiveSheet, so I can run the same macro as all data is in the 'data' worksheet. Hope someone can help

Sub test_copy()
Dim a, i As Long, txt As String
a = Sheets("data").Range("a1").CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
txt = a(i, 2) & ";;" & a(i, 3)
.Item(txt) = a(i, 4)
Next
a = ActiveSheet.Range("a1").CurrentRegion.Resize(, 4).Value
For i = 1 To UBound(a, 1)
txt = a(i, 1) & ";;" & a(i, 2)
If .exists(txt) Then
a(i, 4) = .Item(txt)
Else
a(i, 4) = ""
End If
Next
End With
ActiveSheet.Range("a1").CurrentRegion.Resize(, 4).Value = a
End Sub

--------------------
datasheet below
--------------------
Excel 2007
ABCDEFGHIJKLMN
1sawing machine
210056901/10/20120.10.250.890.250.220.140.560.470.580.450.47
310056902/10/20120.20.250.890.250.220.140.560.470.580.450.47
410056903/10/20120.30.250.890.250.220.140.560.470.580.450.47
510056904/10/20120.40.250.890.250.220.140.560.470.580.450.47
610056905/10/20120.50.250.890.250.220.140.560.470.580.450.47
710056906/10/20120.60.250.890.250.220.140.560.470.580.450.47
810056907/10/20120.70.250.890.250.220.140.560.470.580.450.47
910056908/10/20120.80.250.890.250.220.140.560.470.580.450.47
1010056909/10/20120.90.250.890.250.220.140.560.470.580.450.47
1110056910/10/201210.250.890.250.220.140.560.470.580.450.47
1210056911/10/20121.10.250.890.250.220.140.560.470.580.450.47
1310056912/10/20121.20.250.890.250.220.140.560.470.580.450.47
1410056913/10/20121.30.250.890.250.220.140.560.470.580.450.47
1510056914/10/20121.40.250.890.250.220.140.560.470.580.450.47
1610056915/10/20121.50.250.890.250.220.140.560.470.580.450.47
1710056916/10/20121.60.250.890.250.220.140.560.470.580.450.47
1810056917/10/20121.70.250.890.250.220.140.560.470.580.450.47
1910056918/10/20121.80.250.890.250.220.140.560.470.580.450.47
2010056919/10/20121.90.250.890.250.220.140.560.470.580.450.47
2110056920/10/201220.250.890.250.220.140.560.470.580.450.47
2210056921/10/20122.10.250.890.250.220.140.560.470.580.450.47
2310056922/10/20122.20.250.890.250.220.140.560.470.580.450.47
24lathe machine
2510025601/10/20123.10.250.890.250.220.140.560.470.580.450.47
2610025602/10/20123.20.250.890.250.220.140.560.470.580.450.47
2710025603/10/20123.30.250.890.250.220.140.560.470.580.450.47
2810025604/10/20123.40.250.890.250.220.140.560.470.580.450.47
2910025605/10/20123.50.250.890.250.220.140.560.470.580.450.47
3010025606/10/20123.60.250.890.250.220.140.560.470.580.450.47
3110025607/10/20123.70.250.890.250.220.140.560.470.580.450.47
3210025608/10/20123.80.250.890.250.220.140.560.470.580.450.47
3310025609/10/20123.90.250.890.250.220.140.560.470.580.450.47
3410025610/10/201240.250.890.250.220.140.560.470.580.450.47
3510025611/10/20124.10.250.890.250.220.140.560.470.580.450.47
3610025612/10/20124.20.250.890.250.220.140.560.470.580.450.47
3710025613/10/20124.30.250.890.250.220.140.560.470.580.450.47
3810025614/10/20124.40.250.890.250.220.140.560.470.580.450.47
3910025615/10/20124.50.250.890.250.220.140.560.470.580.450.47
4010025616/10/20124.60.250.890.250.220.140.560.470.580.450.47
4110025617/10/20124.70.250.890.250.220.140.560.470.580.450.47
4210025618/10/20124.80.250.890.250.220.140.560.470.580.450.47
4310025619/10/20124.90.250.890.250.220.140.560.470.580.450.47
4410025620/10/201250.250.890.250.220.140.560.470.580.450.47
4510025621/10/20125.10.250.890.250.220.140.560.470.580.450.47
4610025622/10/20125.20.250.890.250.220.140.560.470.580.450.47
47drilling machine
484589601/10/20126.11.252.30.250.220.140.560.470.580.450.47
494589602/10/20126.21.252.30.250.220.140.560.470.580.450.47
504589603/10/20126.31.252.30.250.220.140.560.470.580.450.47
514589604/10/20126.41.252.30.250.220.140.560.470.580.450.47
524589605/10/20126.51.252.30.250.220.140.560.470.580.450.47
534589606/10/20126.61.252.30.250.220.140.560.470.580.450.47
544589607/10/20126.71.252.30.250.220.140.560.470.580.450.47
554589608/10/20126.81.252.30.250.220.140.560.470.580.450.47
564589609/10/20126.91.252.30.250.220.140.560.470.580.450.47
574589610/10/201271.252.30.250.220.140.560.470.580.450.47
584589611/10/20127.11.252.30.250.220.140.560.470.580.450.47
594589612/10/20127.21.252.30.250.220.140.560.470.580.450.47
604589613/10/20127.31.252.30.250.220.140.560.470.580.450.47
614589614/10/20127.41.252.30.250.220.140.560.470.580.450.47
624589615/10/20127.51.252.30.250.220.140.560.470.580.450.47
634589616/10/20127.61.252.30.250.220.140.560.470.580.450.47
644589617/10/20127.71.252.30.250.220.140.560.470.580.450.47
654589618/10/20127.81.252.30.250.220.140.560.470.580.450.47
664589619/10/20127.91.252.30.250.220.140.560.470.580.450.47
674589620/10/201281.252.30.250.220.140.560.470.580.450.47
684589621/10/20128.11.252.30.250.220.140.560.470.580.450.47
694589622/10/20128.21.252.30.250.220.140.560.470.580.450.47

<COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
data



-----------------------
machine sheet
-----------------------

Excel 2007
ABC
110056923/09/2010
210056924/09/2010
310056925/09/2010
410056926/09/2010
510056927/09/2010
610056928/09/2010
710056929/09/2010
810056930/09/2010
910056901/10/2010
1010056902/10/2010
1110056903/10/2010
1210056904/10/2010
1310056905/10/2010
1410056906/10/2010
1510056907/10/2010
1610056908/10/2010
1710056909/10/2010
1810056910/10/2010
1910056911/10/2010
2010056912/10/2010
2110056913/10/2010
2210056914/10/2010
2310056915/10/2010
2410056916/10/2010
2510056917/10/2010
2610056918/10/2010
2710056919/10/2010
2810056920/10/2010
2910056921/10/2010
3010056922/10/2010
3110056923/10/2010
3210056924/10/2010
3310056925/10/2010
3410056926/10/2010
3510056927/10/2010
3610056928/10/2010
3710056929/10/2010
3810056930/10/2010

<COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0"><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
saw



cheers
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi there,
Is anyone able to help me out or see an obvious mistake as to why the macro does not work please?

much appreciate any help
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

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