VBA - Paste tables under each other with 1 lane space between

Josu

New Member
Joined
Mar 2, 2021
Messages
39
Office Version
  1. 2010
Platform
  1. Windows
I currently have small project and I trying to figure out how to paste to "Dynamic Range" inserting 1 lane of space between pasted date
Basically location to paste always will be moved either up or down
VBA Code:
Sub CopyTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Test")
ws.Activate
With ThisWorkbook.Worksheets("Test")
Dim lr As Long
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
'   Copy range
    Range("A1:G" & lr).copy
End With

End Sub

Sub PasteTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Email")
ws.Activate
With ThisWorkbook.Worksheets("Email")
Range("A1").PasteSpecial xlPasteAll
End With
End Sub
Basically I need 1 lane of space after last cell with data in column A
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I'm away from my laptop at the moment so this is untested, but try the following:
VBA Code:
Option Explicit
Sub CopyUnder()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Test")
    Set ws2 = Worksheets("Email")
   
   ws1.Range("A1", ws1.Cells(Rows.Count, "G").End(xlUp)).Copy
   With ws2.Cells(Rows.Count, 1).End(xlUp).Offset(2)
      .PasteSpecial xlPasteValuesAndNumberFormats
      .PasteSpecial xlPasteFormats
   Application.CutCopyMode = False
   End With
End Sub
 
Upvote 1
Solution
Try this. A small change to your code.
VBA Code:
Sub CopyTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Test")
ws.Activate
With ThisWorkbook.Worksheets("Test")
Dim lr As Long
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
'   Copy range
    Range("A1:G" & lr).copy
End With

End Sub

Sub PasteTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Email")
ws.Activate
With ThisWorkbook.Worksheets("Email")
Range(ws.Cells(ws.UsedRange.Rows.Count) + 1, 1)).PasteSpecial xlPasteAll
End With
End Sub
 
Upvote 0
Actually second part of code which I using, copied wrong part initially and can't edit main message now
VBA Code:
Sub PasteTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Email")
ws.Activate
With ThisWorkbook.Worksheets("Email")
Dim lr As Long
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & lr).PasteSpecial xlPasteAll
End With
End Sub
 
Upvote 0
Anyone can help with this?
Still cannot figure out how to win this fight
 
Upvote 0
If I understand you correctly, you want to copy a 'table' (probably a range?) from the sheet "Test" from A1 to the last row in column G, and paste it to the sheet "Email" under some existing data? If that's it, try the following:

VBA Code:
Option Explicit
Sub CopyUnder()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Test")
    Set ws2 = Worksheets("Email")
    
    ws1.Range("A1", ws1.Cells(Rows.Count, "G").End(xlUp)).Copy _
    ws2.Cells(Rows.Count, 1).End(xlUp).Offset(2)
End Sub
 
Upvote 0
If I understand you correctly, you want to copy a 'table' (probably a range?) from the sheet "Test" from A1 to the last row in column G, and paste it to the sheet "Email" under some existing data? If that's it, try the following:

VBA Code:
Option Explicit
Sub CopyUnder()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Test")
    Set ws2 = Worksheets("Email")
  
    ws1.Range("A1", ws1.Cells(Rows.Count, "G").End(xlUp)).Copy _
    ws2.Cells(Rows.Count, 1).End(xlUp).Offset(2)
End Sub
Basically with copy there is no issue
Problem is with PASTE after, as I need to have extra row of space between as I repeat this paste 3 times in same sheet

VBA Code:
Sub PasteTest()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Email")
ws.Activate
With ThisWorkbook.Worksheets("Email")
Dim lr As Long
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    Range("A" & lr).PasteSpecial xlPasteAll
End With
End Sub
In this code I need somehow to paste not in last row with data, but last row with data +1 row (to have empty space)
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,193
Members
449,213
Latest member
Kirbito

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