Finding matching date in column and pasting in that row

01MooKy

New Member
Joined
Jan 27, 2025
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I'm trying to create a macro. Lets say I have 2 sheets, Sheet 1 and Sheet 2. In Sheet 1, column A, cells A1 to A31 are just dates from Jan 1 - 31, 2025. Sheet 2, I have a single row of data in row 1, with cell A1 containing the date 1/22/2025.

I would like to copy the row of data in Sheet 2 and then have it find the matching date from cell A1 of Sheet 2 to the date in Sheet 1 column A and paste it in that row of Sheet 1, which should be cell A22. It doesn't matter if it overwrites the date in Sheet 1 when it pastes since it should be the exact same date.

I hope that makes sense.

Thanks,
K
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi and welcome to MrExcel

Try this:
VBA Code:
Sub copyrow()
  Dim f As Range
 
  Set f = Sheets("Sheet1").Range("A:A").Find(Sheets("Sheet2").Range("A1").Value, , xlFormulas, xlWhole)
  If f Is Nothing Then
    MsgBox "Date not exists"
  Else
    Sheets("Sheet2").Rows(1).Copy Sheets("Sheet1").Range("A" & f.Row)
  End If
End Sub
 
Upvote 1
Solution
Hi and welcome to MrExcel

Try this:
VBA Code:
Sub copyrow()
  Dim f As Range
 
  Set f = Sheets("Sheet1").Range("A:A").Find(Sheets("Sheet2").Range("A1").Value, , xlFormulas, xlWhole)
  If f Is Nothing Then
    MsgBox "Date not exists"
  Else
    Sheets("Sheet2").Rows(1).Copy Sheets("Sheet1").Range("A" & f.Row)
  End If
End Sub
Thank you! It worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,226,017
Messages
6,188,441
Members
453,474
Latest member
th9r

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