Bit of a dinosaur?

litestream

Active Member
I need to copy some data from my stock entrysheet "STORAGE DELIVERY SHEET" to my Archive "MOVEMENT HISTORY"
Unfortunately, some of the data needs to appear in different rows from the original. The following code works fine for one row, but there are 27 rows on my entry sheet and I was wondering if this could be simplified

EndRow = Sheets("MOVEMENT HISTORY").Range("A65536").End(xlUp).Row + 1
Sheets("STORAGE DELIVERY SHEET").Range("A17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("A" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("B17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("B" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("C17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("C" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("E17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("E" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("G17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("D" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("H17").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("F" & EndRow & "")
Sheets("STORAGE DELIVERY SHEET").Range("S1").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("G" & EndRow & "")

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Completely untested, since you haven't posted a sample of your data, but something along these lines should do the trick...

Code:
``````Sub test()
Dim EndRow As Long
Dim i, c As Integer

EndRow = Sheets("MOVEMENT HISTORY").Range("A65536").End(xlUp).Row + 1

For i = 17 To 44
c = 0
Do
Sheets("STORAGE DELIVERY SHEET").Range("A" & i & ":H" & i).Copy Destination:=Sheets("MOVEMENT HISTORY").Range("A" & EndRow + c & "")
i = i + 1
c = c + 1
Loop
Next i

Sheets("STORAGE DELIVERY SHEET").Range("S1").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("G" & EndRow & "")

End Sub``````

Hi,

this is a start to get it more readable
depending on your needs further enhancements are possible
Code:
``````Option Explicit

Sub test()
Dim shStorage As Worksheet
Dim shHistory As Worksheet
Dim EndRow As Long

Set shStorage = Sheets("STORAGE DELIVERY SHEET")
Set shHistory = Sheets("MOVEMENT HISTORY")

EndRow = shHistory.Cells(Rows.Count, "A").End(xlUp).Row + 1

With shStorage
.Range("A17").Copy shHistory.Range("A" & EndRow)
.Range("B17").Copy shHistory.Range("B" & EndRow)
.Range("C17").Copy shHistory.Range("C" & EndRow)
.Range("E17").Copy shHistory.Range("E" & EndRow)
.Range("G17").Copy shHistory.Range("D" & EndRow)
.Range("H17").Copy shHistory.Range("F" & EndRow)
.Range("S1 ").Copy shHistory.Range("G" & EndRow)
End With

End Sub``````
TIP: please use the codebutton to display code

what would be the next row code
is it this ?
Code:
``Sheets("STORAGE DELIVERY SHEET").Range("A18").Copy Destination:=Sheets("MOVEMENT HISTORY").Range("A" & EndRow + 1)``
so just adding 1 to all rows ?

kind regards,
Erik

Hi litestream

A suggestion: Use a Look-up Table. It makes it easy to read and update the correspondences between the addresses in the first and the second sheets.

Hope this helps
PGC

Code:
``````Option Explicit
Option Base 1

Sub Copy_Data()
Dim shMov As Worksheet, shSto As Worksheet
Dim LuT(), EndRow As Long, i As Integer

LuT = Array( _
Array("A", "A17"), _
Array("B", "B17"), _
Array("C", "C17"), _
Array("D", "E17"), _
Array("E", "G17"), _
Array("F", "H17"), _
Array("G", "S1"))

Set shSto = Sheets("STORAGE DELIVERY SHEET")
Set shMov = Sheets("MOVEMENT HISTORY")

EndRow = shMov.Range("A65536").End(xlUp).Row + 1

For i = 1 To UBound(LuT, 1)

shMov.Range(LuT(i)(1) & EndRow) = shSto.Range(LuT(i)(2))

Next i
End Sub``````

Thanks all, I'll try the ideas out.

Replies
11
Views
520
Replies
2
Views
784
Replies
4
Views
1K
Replies
50
Views
2K
Replies
2
Views
342

1,217,681
Messages
6,137,951
Members
450,100
Latest member
mscetr

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.

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

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