Copy first two cells in row vs whole row

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
544
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am using this code to copy any rows in Sheet 1 with a value in B:B to Sheet 2. I altered the code so far to suit my needs but I only need to copy the date from Column A and B from Sheets 1 and paste into Sheet 2, not the entire row. Anyone know how to do this? I assume I need to change matchRow to something else... THANKS!!

Code:
Sub Test()
'Copies values from row if designated value is found in Column B
Sheets("Sheet1").Select
For Each Cell In Sheets("Sheet1").Range("B:B")
    If Cell.Value > "" Then
        matchRow = Cell.Row
        Rows(matchRow & ":" & matchRow).Select
        Selection.Copy
'Pastes values to next empty Row
Sheets("Sheet2").Select
       Sheets("Sheet2").Range("A1").Select
            Selection.End(xlDown).Select
            ActiveCell.Offset(1, 0).Select
            ActiveSheet.Paste
        Sheets("Sheet1").Select
    End If
Next
End Sub
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Depending on what you already have in sheet2 , try this:-
Code:
Sheets("Sheet1").Range("A:B").Copy Sheets("Sheet2").Range("A1")
Sheets("Sheet2").Range("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0
This does work, but there is also another variable I should have mentioned. I eventually want copy the data to Sheet 2 in E1 not A1. This is due to necessary data in Columns A:D, so I cannot delete rows. The way you did it was an abbreviation of how I was doing it before until I realized my issue. Thanks for helping though, greatly appreciated!!
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
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