Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default looping thru rows of variable length

I used vba to import a tab delimited text file.
I need to automatically do calcs on the data.
My A column has data in variable lengths in the following format
(beginning with Cell A22):

[Step 1]
time
12:00
12:02
12:04
12:06

[Step 2]
time
13:00
13:02
13:04
13:06
13:08

[Step X] Variable amount of steps and data
time
13:00
13:02
13:04
13:06


I want to put in a column the elapsed time for the data in each step,
restarting the time elapsed at 0 for each step.
So the first value would have 0. So in K24 I would have 0, in K25 I
would have A25-$A$24.
I am not sure how to loop and test to see if I need to start over
again with the next [Step]
I assume I need to anchor the first time reading after the word "time"
then use that to subtract from each other value untile a blank row is
found. Then start over.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default looping thru rows of variable length

Hi

This should do it, just remember to format column K as time to show results
correct.

Sub test()
Dim StepStart As Range
Dim off As Long
Set StepStart = Range("A22")
off = 2

Do
If StepStart.Offset(off, 0).Value < "" Then
If Not IsNumeric(StepStart.Offset(off - 1).Value) Then
StepStart.Offset(off, 10) = 0
Else
StepStart.Offset(off, 10).Value = StepStart.Offset(off,
0).Value - _
StepStart.Offset(off - 1, 0).Value
End If
off = off + 1
Else
Set StepStart = StepStart.Offset(off + 2)
off = 2
End If
Loop Until StepStart.Value = ""
End Sub

Regards,
Per
"gtslabs" skrev i meddelelsen
...
I used vba to import a tab delimited text file.
I need to automatically do calcs on the data.
My A column has data in variable lengths in the following format
(beginning with Cell A22):

[Step 1]
time
12:00
12:02
12:04
12:06

[Step 2]
time
13:00
13:02
13:04
13:06
13:08

[Step X] Variable amount of steps and data
time
13:00
13:02
13:04
13:06


I want to put in a column the elapsed time for the data in each step,
restarting the time elapsed at 0 for each step.
So the first value would have 0. So in K24 I would have 0, in K25 I
would have A25-$A$24.
I am not sure how to loop and test to see if I need to start over
again with the next [Step]
I assume I need to anchor the first time reading after the word "time"
then use that to subtract from each other value untile a blank row is
found. Then start over.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default looping thru rows of variable length


Per Jessen code will notlop unless there is a value in A22

Try this macro

Sub CalcTime()
Dim lLR As Long
Dim l4Row As Long
Dim rStart As Range

lLR = Cells(Rows.Count, "a").End(xlUp).Row

For l4Row = 1 To lLR Step 1
If IsNumeric(Cells(l4Row, "a").Value) And Not Cells(l4Row, "a") =
"" Then
If rStart Is Nothing Then
Set rStart = Cells(l4Row, "a")
End If
With Cells(l4Row, "b")
..Value = Cells(l4Row, "a").Value - rStart.Value
..NumberFormat = "h:mm"
End With
Else
Set rStart = Nothing
End If
Next l4Row
End Sub


--
mudraker

If my reply has assisted or failed to assist you I welcome your
Feedback.

www.thecodecage.com
------------------------------------------------------------------------
mudraker's Profile: http://www.thecodecage.com/forumz/member.php?userid=18
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=44048

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide rows variable row length anduare2 Excel Programming 2 April 15th 08 03:20 PM
Reading Rows of Variable Length DCondie Excel Programming 2 November 13th 04 03:54 PM
Counting Variable Length of Rows in a Named Range jandre[_2_] Excel Programming 0 October 28th 04 06:26 PM
Counting Variable Length of Rows in a Named Range jandre[_3_] Excel Programming 0 October 28th 04 06:24 PM
Counting Variable Length of Rows in a Named Range jandre Excel Programming 1 October 28th 04 05:27 PM


All times are GMT +1. The time now is 10:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"