VBA, copy & past specific columns to prevent overwriting of existing data

excelquestion8

New Member
Joined
Feb 9, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi, I would like to only copy and paste columns A - L into another tab instead of the whole row. I would like to prevent overwriting data in columns after L. Here is my code:

VBA Code:
Sub CopyName()
Dim Check As Range, r As Long, lastrow2 As Long, lastrow As Long, lastrow3 As Long, lastrow4 As Long
Application.ScreenUpdating = False
lastrow = Worksheets("Assignments").UsedRange.Rows.Count
lastrow2 = Worksheets("name1").UsedRange.Rows.Count
lastrow3 = Worksheets("name2").UsedRange.Rows.Count
lastrow4 = Worksheets("name3").UsedRange.Rows.Count

If lastrow2 = 1 Then lastrow2 = 0
    For r = lastrow To 2 Step -1
        If Range("E" & r).Value = "name1" Then
            Rows(r).Copy Destination:=Worksheets("name1").Range("A" & lastrow2 + 2)
            lastrow2 = lastrow2 + 1
            Else:
        End If
    Next r
If lastrow3 = 1 Then lastrow3 = 0
    For r = lastrow To 2 Step -1
         If Range("E" & r).Value = "name2" Then
            Rows(r).Copy Destination:=Worksheets("name2").Range("A" & lastrow3 + 2)
            lastrow3 = lastrow3 + 1
            Else:
        End If
    Next r
If lastrow4 = 1 Then lastrow4 = 0
    For r = lastrow To 2 Step -1
         If Range("E" & r).Value = "name3" Then
            Rows(r).Copy Destination:=Worksheets("name3").Range("A" & lastrow4 + 2)
            lastrow4 = lastrow4 + 1
            Else:
        End If
    Next r

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,057
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
You can do that like
VBA Code:
Range("A"& r).Resize(, 12).Copy Destination:=Worksheets("name1").Range("A" & lastrow2 + 2)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,057
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,032
Messages
5,767,739
Members
425,429
Latest member
MMMMMM

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
Top