Solved

Excel Search Time column return time value and value

Posted on 2016-08-04
5
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 51

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 51

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

691 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