Insert Range of cells from one sheet to another with shifting cells down.

PitMax

New Member
Joined
May 12, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am looking for the VBA that will copy and insert the range of cells from one sheet to another within the same workbook.

Ideally would be to run macro with button on the source sheet.

Source sheet.png


All items should be copied and inserted to blank document. The number of items (rows) in source sheet might be different (1~300). If it helps, I have available the cell that counts the number of lines (rows) that should be inserted.
blank document.png

After press the button, the ready document should have all items inserted and the cells in columns B8:F8 should be shifted down.

ready document.png


It is important to keep document formatting (border lines, font etc.)

It would be great If I could also back to blank document.

Does anyone know how it can be done?

Thank you in advance :)
 
Ok. maybe too many inquiries . Let's focus on the basis.

I have found one small issue. When I have one item (one row), the Run-Time error '1004' appears:
Debug - error.png


What should be amend in the code to:
1) Copy and insert 11 columns.

2) run the button on the sheet 3 to copy from sheet1 to sheet2 and Sheet4?

Cheers,
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
VBA Code:
Sub test()
    Dim rng As Range
    Dim lr&
    With Sheets("Sheet2")
        lr = .Cells(Rows.Count, 5).End(xlUp).Row - 7
        If lr > 1 Then
            With .Cells(7, 2)
                .Resize(lr, 11).ClearContents
                .Resize(lr - 1, 11).Delete xlUp
            End With
        End If
    End With
    Range("A3:K3").Resize(Cells(Rows.Count, 1).End(xlUp).Row - 2).Copy
    Sheets("Sheet2").Range("B7").Insert Shift:=xlDown
End Sub
 
Upvote 0
VBA Code:
Sub test()
    Dim rng As Range
    Dim lr&
    With Sheets("Sheet2")
        lr = .Cells(Rows.Count, 5).End(xlUp).Row - 7
        If lr > 1 Then
            With .Cells(7, 2)
                .Resize(lr, 11).ClearContents
                .Resize(lr - 1, 11).Delete xlUp
            End With
        End If
    End With
    With Sheets("Sheet1")
    .Range("A3:K3").Resize(.Cells(Rows.Count, 1).End(xlUp).Row - 2).Copy
    End With
    Sheets("Sheet2").Range("B7").Insert Shift:=xlDown
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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