VBA code to copy and paste range into next empty row on another sheet

Katyjean1

New Member
Joined
Apr 30, 2019
Messages
12
I found this code to copy/paste a range from sheet 1 to sheet 2 onto the next empty row. It was working great until I switched to office 365. Now it won't paste onto the next empty row. Can anyone tell me what's wrong with it? Thanks!
Code:
 Sub SUBMIT2()
 
  Dim copySheet As Worksheet
  Dim pasteSheet As Worksheet


  Set copySheet = Worksheets("Entry Form")
  Set pasteSheet = Worksheets("Distribution")


  copySheet.Range("F16:P26").Copy
  pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlValues
  Application.CutCopyMode = False
  
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Seems ok to me. Are you getting any error messages? What happens when you step through the code, ie. F8 ?

Open the VBE. Click on Tools. References. Do any of the lines indicate you are missing a reference. If so, fix it by scrolling down to the reference and add it in.
 
Upvote 0
No errors are indicated when I step through the code. Each line is highlighted in yellow, but no missing references. I don't understand why this code stopped working after I switched to Office 365. It still pastes values but it doesn't paste onto the next empty row.
 
Upvote 0
Hi & welcome to MrExcel
In that case, where is it pasting the data?
 
Last edited:
Upvote 0
On top of the previously pasted data. I think I just realized what the error is. The row I'm pasted doesn't always have data in column A. Is that what's causing the error? Since the data in column A doesn't always have data it's being considered as the next empty row?
 
Upvote 0
Try this:

Code:
 Sub SUBMIT2()
 
  Dim copySheet As Worksheet
  Dim pasteSheet As Worksheet
  Dim lr As Long
  


  Set copySheet = Worksheets("Entry Form")
  Set pasteSheet = Worksheets("Distribution")




  copySheet.Range("F16:P26").Copy
  lr = pasteSheet.Range("J" & Rows.Count).End(xlUp).Row
  pasteSheet.Range("A" & lr + 1).PasteSpecial xlValues
  Application.CutCopyMode = False
  
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,363
Messages
6,124,505
Members
449,166
Latest member
hokjock

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