Having difficulty copying a range of cells to another WS in same book at one row underneath last used row

Desmondo

Board Regular
Joined
Feb 27, 2013
Messages
70
I have been at this now for days now trying everything i can find and adapting it.

I want to copy data from one sheet to another at exactly one row beneath the last used row in the store sheet. I have had mixed results but none that i can find does exactly what i need and looking for some helpful pointers.

ws1 one is temp storage and ws2 is the store, when i click submit i want the used range from ws1 to be added to the row under the last used row of sheet2. This will be a continuous thing with more entries.

This is what i have so far and really hope someone here can help?

Code:
Sub moveDataToStore()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim LastRow
Dim myRange As Range




Set ws1 = Sheets("Temp")
Set ws2 = Sheets("Store")




myRange = ws1.UsedRange.CurrentRegion


With myRange


If Sheets("Store").Range("A1").Value = "" Then


.Copy Destination:=ws2.Cells(1, 1)


Else


LastRow = ws2.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row


.Copy Destination:=ws2.Cells(LastRow + 1).Row


End If




End With






ws1.Range("A:G") = ""
 
Exact sheet names are "Temp" and "Store", i want to copy from "Temp" to "Store" without overwriting whats in "Store" thanks
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Now like I said before and you never responded as to if this was true.
This script assumes there is always data in column "A" of each row. If that is not true then this may not work.
And then I would need to know what column always has date on each row.
Code:
Sub Copy_Sheet1_To_Sheet2()
'Modified 1-30-18 7:40 PM EST
Application.ScreenUpdating = False
Dim One As Long
Sheets("Temp").Activate
One = 1
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("Temp").Cells(Rows.Count, "A").End(xlUp).Row
Lastrowa = Sheets("Store").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Temp").Rows(One & ":" & Lastrow).Copy Sheets("Store").Rows(Lastrowa)
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You could put this as part of the code before you start the copy/paste bit.
Code:
Dim lr As Long, ws2 As Worksheet
Set ws2 = Worksheets("Store")
If WorksheetFunction.CountA(ws2.Cells) = 0 Then
lr = 1
Else
lr = ws2.Cells.Find("*", , , , xlByRows, xlPrevious).Offset(1).Row
End If
 
Upvote 0
What is the result of this?
Code:
Dim lr As Long, ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Worksheets("Temp")
Set ws2 = Worksheets("Store")
If WorksheetFunction.CountA(ws2.Cells) = 0 Then
lr = 1
Else
lr = ws2.Cells.Find("*", , , , xlByRows, xlPrevious).Offset(1).Row
End If
ws1.UsedRange.Copy ws2.Cells(lr, 1)
 
Upvote 0
What is the result of this?
Code:
Dim lr As Long, ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Worksheets("Temp")
Set ws2 = Worksheets("Store")
If WorksheetFunction.CountA(ws2.Cells) = 0 Then
lr = 1
Else
lr = ws2.Cells.Find("*", , , , xlByRows, xlPrevious).Offset(1).Row
End If
ws1.UsedRange.Copy ws2.Cells(lr, 1)

Hi sorry I fell asleep as 1 in the morning. I will try today and the column with data in it is column b. Thanks again
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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