View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Hutchins Tom Hutchins is offline
external usenet poster
 
Posts: 1,069
Default Excel Macro Help

Here is a macro that should do what you want.

Sub CountEtc()
Dim LR As Long
Dim Rcount As Long, Lcount As Long
Dim FirstN As Date, SecondN As Date
Dim CurrChar As String, NextChar As String
'find last row
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
'initialize variables
Rcount = 0
Lcount = 0
'walk down column A
Range("A1").Activate
Do While ActiveCell.Row <= LR
CurrChar$ = UCase(ActiveCell.Offset(0, 4).Value)
NextChar$ = UCase(ActiveCell.Offset(1, 4).Value)
Select Case CurrChar$
Case "N"
If (NextChar$ = "L") Or (NextChar$ = "R") Then
FirstN = ActiveCell.Value
End If
Case "L"
Lcount = Lcount + 1
If NextChar$ = "N" Then
SecondN = ActiveCell.Offset(1, 0).Value
End If
Case "R"
Rcount = Rcount + 1
If NextChar$ = "N" Then
SecondN = ActiveCell.Offset(1, 0).Value
End If
End Select
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Offset(1, 0).Activate
ActiveCell.Value = "TOTAL there are " & Lcount & " L and " & _
Rcount & " R and time is " & Format((SecondN - FirstN), "h:mm")
End Sub

Hope this helps,

Hutch

"Nils Titley" wrote:

I need to process an Excel file. I want to run a macro. The macro will not
know how many rows are in the file. The column A has a date time stamp for
each row.

Column E has the value N, L, or R. The rows will start with Ns. Than the
rows will have L or Rs. The last rows will have Ns. When the rows start to
have L or Rs. I need to grab the date time and when the N begin again I need
the date time so I can calculate the total time and add up the number of L
and Rs.

Here is a short example.

1/1/2008 10:10 N
1/1/2008 10:11 N
1/1/2008 10:12 N
1/1/2008 10:13 L
1/1/2008 10:14 R
1/1/2008 10:15 L
1/1/2008 10:16 N
1/1/2008 10:17 N

Total there are 2 L and 1 R and time is 4 min.

If this is not the right place for this please direct me to the correct place.

Point me in the right direction to find help.

Thank you for your assistance.