+ Reply to Thread
Results 1 to 2 of 2

Matching Date and Time Stamped Data between worksheets

  1. #1
    Registered User
    Join Date
    09-19-2013
    Location
    East Lansing, Mi
    MS-Off Ver
    windows 8
    Posts
    2

    Matching Date and Time Stamped Data between worksheets

    Hi all thanks for the help in advance,

    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 off 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.

  2. #2
    Registered User
    Join Date
    09-19-2013
    Location
    East Lansing, Mi
    MS-Off Ver
    windows 8
    Posts
    2

    Re: Matching Date and Time Stamped Data between worksheets

    I have this so far but it takes way to long to run. I wonder if I should use the Vlookup function to sort for date and time matches or go about it in another fashion. Any help would be tremendously appreciated

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Modifying Date/Time stamped value to calculate Days Since
    By mando415 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 05:10 PM
  2. Replies: 3
    Last Post: 11-24-2012, 03:19 PM
  3. [SOLVED] Averaging inconsistent time-stamped data
    By Dave Bn in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-25-2012, 04:55 PM
  4. [SOLVED] Binning Time Stamped Data into Intervals
    By pickslides in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-29-2012, 05:48 PM
  5. Time stamped data
    By Cspotrun in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-03-2007, 01:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1