Solved

Excel Search Time column return time value and value

Posted on 2016-08-04
5
33 Views
Last Modified: 2016-08-27
I have an excel spreadsheet with three columns
A Time column
A Id Column
A value column

There is a row of data generated every second.

I would like some VBA code that will scan a time column for whole minutes and copy the time value, ID and value to new columns.
In the attached file the times will be minutes 1 to 10 on a full data set this would occur across 24 hours.
samplebook.xlsx
0
Comment
Question by:OST-IS
  • 2
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 400 total points (awarded by participants)
ID: 41742347
Hi,

pls try
Sub macro()
Rw = 1
For Each c In Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    If TimeValue(c.Text) = TimeSerial(Hour(c), Minute(c), 0) Then
        Sheets("Sheet2").Range("A" & Rw) = c
        Sheets("Sheet2").Range("A" & Rw).NumberFormat = c.NumberFormat
        Sheets("Sheet2").Range("B" & Rw) = c.Offset(, 1)
        Sheets("Sheet2").Range("C" & Rw) = c.Offset(, 2)
        Rw = Rw + 1
    End If
Next
End Sub

Open in new window

Regards
0
 
LVL 18

Assisted Solution

by:xtermie
xtermie earned 100 total points (awarded by participants)
ID: 41742352
Hey OST-IS...Don't think you need VBA code, you can do this in a second sheet with functions
Check the sample attached
Result spreadsheet gets minute form Time column and then fills in the ID and value to new columns in the Result spreadsheet.  All you have to do is copy down the formulas.

Hope this helps
samplebook_example.xlsx
0
 
LVL 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 400 total points (awarded by participants)
ID: 41742354
In the same Sheet
Sub macro()
Rw = 1
For Each c In Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    If TimeValue(c.Text) = TimeSerial(Hour(c), Minute(c), 0) Then
        Range("F" & Rw) = c
        Range("F" & Rw).NumberFormat = c.NumberFormat
        Range("G" & Rw) = c.Offset(, 1)
        Range("H" & Rw) = c.Offset(, 2)
        Rw = Rw + 1
    End If
Next
End Sub

Open in new window

2
 

Author Comment

by:OST-IS
ID: 41743551
Great solution can be modified easily to suit other solutions great job. Rgonzo
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41772809
Best solution by Rgonzo
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question