Bit of a dinosaur?

litestream

Active Member
Joined
Jul 24, 2006
Messages
323
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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