VBA Code - Copy set range and paste in the next blank row (skipping 1 row)

Franchise1979

New Member
Joined
Jan 5, 2023
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hi All, I have a very small and easy spreadsheet in which I am trying to do a macro for the following:

1) Copy cells B5:J19 (including formats)
2) find the next row with no data
3) paste in the next row with no data (but skipping 1 more row so there is a space)

Here is the code I am using:

VBA Code:
Sub PasteSource()
  Application.ScreenUpdating = False
  Dim copySheet As Worksheet
  Dim pasteSheet As Worksheet

  Set copySheet = Worksheets("Sheet1")
  Set pasteSheet = Worksheets("Sheet1")

  copySheet.Range("B5:J18").Copy
  pasteSheet.Cells(Rows.Count, 6).End(xlUp).Offset(2, 0).PasteSpecial xlPasteValues
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
End Sub



The offset 2 I know is adding the extra row I need but for some reason, it is pasting the data (values only, which I know I have PasteValues in the code) 4 columns over to the right.

Notes:
1) I am perfectly fine copying the entire rows (5-19) vs a range
2) The range will always be pasted in the same worksheet
3) Worksheet name could change (so thinking "sheet1" needs to be simply active sheet so I remove sheet naems out of the equation?

Any and all help is appreciated.

Thank you!!!!!
 
Last edited by a moderator:
Does that make more sense explaining it that way?
Yes, thanks. Try this version (still uses the clearing)

VBA Code:
Sub CopyBlock_v4()
  Dim rTopLeft As Range
 
  Set rTopLeft = Range("F" & Rows.Count).End(xlUp).Offset(2, -4)
  Range("B5:J18").Copy Destination:=rTopLeft
  Union(rTopLeft.Resize(14, 4), rTopLeft.Offset(, 5).Resize(14, 3)).ClearContents
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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