Issue Matching Time Stamped Data

simoneug

New Member
Joined
Sep 19, 2013
Messages
2
Hi All, I am having an issue. I have 2 datasets in worksheets in the same workbook say worksheet 1 and worksheet 2. Both Data sets are date and time stamped in columns A and B respectively. I would like to be able to write a macro to search for the matching row of time stamped data in worksheet 1 and 2 then copy both rows of data into a new worksheet, worksheet 3. Not sure if the vlookup function should be used here or if I am better just trying to copy one set of data directly to worksheet 3 and just search for and add the other set of data by matching time stamps. Any help would be greatly appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I have written this so far but it takes far too long to run and I am not sure if the Vlookup function should be used to try to optimize

Sub TimeStampMatch()
Dim cTime As Variant 'CEMS Time
Dim pTime As Variant 'PEMS Time
Dim cD As Variant 'CEMS Date
Dim pD As Variant 'PEMS Date
Dim k As Integer 'row counter for pems date
Dim i As Integer 'cems and paste row counter
Dim j As Integer 'row counter for pems time

i = 1
'first loop through Cems data to find date and time to match
Do Until IsEmpty(ActiveCell.Value)
Sheets(2).Activate

'Reads CEMS Date and Time to search for
cD = Cells(i, 1).Value
cTime = Cells(i, 2).Text

'optional message box's below to display date and time currently looking for
'MsgBox "CEMS DATE" & cD
'MsgBox "CEMS TIME" & cTime
'Select CEMS data to copy
Range(Cells(i, 1), Cells(i, 5)).Select
Selection.Copy
Sheets(1).Activate
Cells(i, 1).Select
ActiveSheet.Paste
Sheets(3).Activate

j = 1
k = 1
pD = Sheets(3).Cells(k, 1)
pTime = Sheets(3).Cells(j, 2).Text

'Nested Loops look to match date stamp first then time stamp
Do Until cD = pD
k = k + 1
pD = Sheets(3).Cells(k, 1)
Loop
If cD = pD Then
j = 1

Do Until cTime = pTime
j = j + 1
pTime = Sheets(3).Cells(j, 2).Text
Loop
If cTime = pTime Then
'Selects matching Pems date and time stamp data to copy
ActiveSheet.Range(Cells(j, 1), Cells(j, 5)).Select
Selection.Copy
Sheets(1).Activate

'Determine offset for pems data paste
Cells(i, 6).Select
ActiveSheet.Paste

End If

End If




i = i + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,050
Messages
6,128,498
Members
449,455
Latest member
jesski

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