Matching Date&Time in 2 sheets

hunter2

New Member
Joined
Nov 24, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all, I am having trouble figuring out how to match Time & Date in 2 different sheets using VBA.

I have 2 sheets.
In Sheet 1, I will generate 1 list of date & time (example of cell A1 "24/11/22 15:20").
I will then copy this data to Sheet 2.

I need a VBA code to verify if cell A1 had already been copied in sheet 2 so I can override and copy from the same cell downwards to A2...3...4...5... etc

Example:
Sheet 1 Cell A1 value : "24/11/22 15:20"
Sheet 1 Cell A2 value : "24/11/22 16:20"

If exact Cell value A1 is found in Sheet 2 column A, row 16 (Sheet 2 A16), I will need to paste Sheet1 A1 to Sheet2 A16 & Sheet1 A2 to Sheet2 A17.
If exact Cell value A1 is NOT found in Sheet 2 column A, I will need to start the paste form last empty cell in Sheet 2 Column A.

Any kind help from the experts is greatly welcomed thank you.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi all, I am having trouble figuring out how to match Time & Date in 2 different sheets using VBA.

I have 2 sheets.
In Sheet 1, I will generate 1 list of date & time (example of cell A1 "24/11/22 15:20").
I will then copy this data to Sheet 2.

I need a VBA code to verify if cell A1 had already been copied in sheet 2 so I can override and copy from the same cell downwards to A2...3...4...5... etc

Example:
Sheet 1 Cell A1 value : "24/11/22 15:20"
Sheet 1 Cell A2 value : "24/11/22 16:20"

If exact Cell value A1 is found in Sheet 2 column A, row 16 (Sheet 2 A16), I will need to paste Sheet1 A1 to Sheet2 A16 & Sheet1 A2 to Sheet2 A17.
If exact Cell value A1 is NOT found in Sheet 2 column A, I will need to start the paste form last empty cell in Sheet 2 Column A.

Any kind help from the experts is greatly welcomed thank you.
1669301732891.png

Long story short, this is the Data I'm dealing with, I need to check if 11/17/22 8:13 (From Sheet 1) already exists in sheet 2, if it does then paste from there, if not continue pasting from lowest fresh empty cell.
 
Upvote 0
This is what I currently have, however it does not work and always will target lowest empty cell and paste from there.

Dim rng2 As Range
Dim rng1 As Range
Dim k As String

Set rng2 = Worksheets("Sheet2").Columns(2)
k = Worksheets("Sheet1").Cells(16, 1)
Set rng1 = rng2.Find(What:=k, LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)


If rng1 Is Nothing Then
Set rng1 = Sheets("Sheet2").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
rng1.PasteSpecial xlPasteValues

Else
rng1.PasteSpecial xlPasteValues



Any help is greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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