View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Kevin B Kevin B is offline
external usenet poster
 
Posts: 1,316
Default Count equal numbers in beginning of a column

I created a custom function to compare the 3 values in 2 different row, if
the values match it returns true, otherwise false.

The function is used in a procedure to determine if a row should be removed.
I marginally tested the code below and it appeared to work.

--------------------------------------------------------------------------------------------------
Function CompVals(Aval1 As Variant, Aval2 As Variant, Aval3 As _
Variant, Bval1 As Variant, Bval2 As Variant, Bval3 As Variant) As Boolean

If Aval1 = Bval1 And Aval2 = Bval2 And Aval3 = Bval3 Then
CompVals = True
Else
CompVals = False
End If

End Function
--------------------------------------------------------------------------------------------------

Sub RemoveRows()

Dim strMS As String
Dim strVal1 As String
Dim strVal2 As String
Dim strVal3 As String
Dim strVal4 As String
Dim strVal5 As String
Dim strVal6 As String
Dim blnIsMatch As Boolean
Dim lRowOffset As Long

Range("A2").Select
strMS = ActiveCell.Value

Do While strMS < ""
strVal1 = ActiveCell.Offset(lRowOffset, 1).Value
strVal2 = ActiveCell.Offset(lRowOffset, 2).Value
strVal3 = ActiveCell.Offset(lRowOffset, 3).Value
strVal4 = ActiveCell.Offset(lRowOffset + 1, 1).Value
strVal5 = ActiveCell.Offset(lRowOffset + 1, 2).Value
strVal6 = ActiveCell.Offset(lRowOffset + 1, 3).Value
blnIsMatch = CompVals(strVal1, strVal2, strVal3, _
strVal4, strVal5, strVal6)
If blnIsMatch Then
ActiveCell.Offset(lRowOffset + 1).EntireRow.Delete
Else
ActiveCell.Offset(1).Select
lRowOffset = 0
strMS = ActiveCell.Value
End If
Loop

End Sub
--------------------------------------------------------------------------------------------------

--
Kevin Backmann


"FiddlerOnTheRoof" wrote:

I have a serie of about 10000 (or more) rows of numbers in several columns.
These numbers are from a log in a machine and there are lognumbers for every
miliseconds. Depending of how long one serie is (how many rows) there are
blocks with equal numbers. A long sequens make 32 equal blocks, a shorter one
16 and so on. I have made a test that takes out equal numbers and leave only
one left. If there are 32 blocks of equal numbers, the test deletes 31 of
them and leave the one in the middle left. This is to prevent to much data in
a workbook.

My problem is that my test depends on how many numbers are equal in every
block. I need to know if there is possible to count equal numbers from the
start of the column so I can give the result to the deleting test.

ms Log1 Log2 Log3

-1 43,09 38,43 54,76
-0,99 43,09 38,43 54,76
-0,98 43,09 38,43 54,76
-0,97 43,09 38,43 54,76
-0,96 43,09 38,43 54,76
-0,95 43,09 38,43 54,76
-0,94 43,09 38,43 54,76
-0,93 43,09 38,43 54,76
-0,92 44,26 39,58 54,03
-0,91 44,26 39,58 54,03
-0,9 44,26 39,58 54,03
-0,89 44,26 39,58 54,03
-0,88 44,26 39,58 54,03
-0,87 44,26 39,58 54,03
-0,86 44,26 39,58 54,03
-0,85 44,26 39,58 54,03