Hi I got a column of numbers i.e. :
[TABLE="width: 64"]
<colgroup><col></colgroup><tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[TABLE="width: 64"]
<colgroup><col></colgroup><tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
Starting from the bottom I want to count and then display results in columns so say :
Row Cells
A B C
1. 3 1 = 4
2. 1 9 = 4
.......... and so on
I want to do it for triplets and so on.
Row Cells
A B C D
1. 3 1 9 = 4
2. 1 9 5 = 4
3. 9 5 3 = 3
They have to be consecutive, with no gaps. So no
3 9 5 = 4
Thanks for anyone who can help.
I got this code as well, I didn't write it just upgraded it.
It counts pairs but in consecutive rows of five numbers in five consecutive columns.
Any way to modify it to do what I want would be of great help, thank you.
[TABLE="width: 64"]
<colgroup><col></colgroup><tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[TABLE="width: 64"]
<colgroup><col></colgroup><tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]9[/TD]
[/TR]
[TR]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
Starting from the bottom I want to count and then display results in columns so say :
Row Cells
A B C
1. 3 1 = 4
2. 1 9 = 4
.......... and so on
I want to do it for triplets and so on.
Row Cells
A B C D
1. 3 1 9 = 4
2. 1 9 5 = 4
3. 9 5 3 = 3
They have to be consecutive, with no gaps. So no
3 9 5 = 4
Thanks for anyone who can help.
I got this code as well, I didn't write it just upgraded it.
It counts pairs but in consecutive rows of five numbers in five consecutive columns.
Any way to modify it to do what I want would be of great help, thank you.
Code:
'=== copy from here ================================='- MACRO TO COUNT PAIRS OF NUMBERS.
'- Numbers contained in a sheet called "Sheet1" ...
'- Columns B to G starting row 2.
'- Needs another blank sheet called "Results"
'- Brian Baulsom August 2004
'====================================================
Dim FromSheet As Worksheet
Dim ToSheet As Worksheet
Dim TempSheet As Worksheet
Dim Fromrow As Long
Dim ToRow As Long
Dim LastRow As Long
Dim Counter As Long
Dim FoundCell As Object
'-
Dim N1 As Integer
Dim N2 As Integer
Dim N3 As Integer
Dim N4 As Integer
Dim N5 As Integer
Dim N1a As Integer
Dim N2a As Integer
Dim N3a As Integer
Dim N4a As Integer
Dim N5a As Integer
'-
Dim CheckStr1 As String
Dim CheckStr2 As String
Dim CheckStr3 As String
Dim CheckStr4 As String
Dim CheckStr5 As String
Dim CheckStr6 As String
Dim CheckStr7 As String
Dim CheckStr8 As String
'------------------------
Sub FindDupes_Click()
Set FromSheet = Worksheets("Sheet1")
LastRow = FromSheet.Range("A65536").End(xlUp).Row
Set TempSheet = Worksheets("TempSheet")
TempSheet.Range("A:Z").ClearContents
Set ToSheet = Worksheets("Results2")
ToSheet.Range("A:Z").ClearContents
Fromrow = 2
ToRow = 1
'-----------------------
'- main loop
'
'-----------------------
' Dla Rzedow od
For Fromrow = 1 To LastRow
Application.StatusBar = _
" Processing row : " & Fromrow & " / " & LastRow
For A = 2 To 6
N1 = FromSheet.Cells(Fromrow, A).Value
For B = A + 1 To 6
N2 = FromSheet.Cells(Fromrow, B).Value
'- Sprawdz ciag z kratek
CheckStr1 = Format(N1, "00") & " - " & Format(N2, "00")
Counter = 1
CheckOtherRows2
If Counter > 1 Then
TempSheet.Cells(ToRow, 1).Value = "'" & CheckStr1
TempSheet.Cells(ToRow, 2).Value = Counter
ToSheet.Cells(ToRow, 1).Value = N1
ToSheet.Cells(ToRow, 2).Value = N2
ToSheet.Cells(ToRow, 3).Value = Counter
ToRow = ToRow + 1
End If
Next
For B = A + 1 To 6
N2 = FromSheet.Cells(Fromrow, B).Value
For c = B + 1 To 6
N3 = FromSheet.Cells(Fromrow, c).Value
'- Sprawdz ciag z kratek
CheckStr3 = Format(N1, "00") & " - " & Format(N2, "00") & " - " & Format(N3, "00")
CheckOtherRows3
If Counter > 1 Then
TempSheet.Cells(ToRow, 3).Value = "'" & CheckStr3
TempSheet.Cells(ToRow, 4).Value = Counter
ToSheet.Cells(ToRow, 5).Value = N1
ToSheet.Cells(ToRow, 6).Value = N2
ToSheet.Cells(ToRow, 7).Value = N3
ToSheet.Cells(ToRow, 8).Value = Counter
ToRow = ToRow + 1
End If
Next
For c = B + 1 To 6
N3 = FromSheet.Cells(Fromrow, c).Value
For d = c + 1 To 6
N4 = FromSheet.Cells(Fromrow, d).Value
'- Sprawdz ciag z kratek
CheckStr5 = Format(N1, "00") & " - " & Format(N2, "00") & " - " & Format(N3, "00") & " - " & Format(N4, "00")
CheckOtherRows4
If Counter > 1 Then
TempSheet.Cells(ToRow, 5).Value = "'" & CheckStr5
TempSheet.Cells(ToRow, 6).Value = Counter
ToSheet.Cells(ToRow, 10).Value = N1
ToSheet.Cells(ToRow, 11).Value = N2
ToSheet.Cells(ToRow, 12).Value = N3
ToSheet.Cells(ToRow, 13).Value = N4
ToSheet.Cells(ToRow, 14).Value = Counter
ToRow = ToRow + 1
End If
Next
For d = c + 1 To 6
N4 = FromSheet.Cells(Fromrow, d).Value
For e = d + 1 To 6
N5 = FromSheet.Cells(Fromrow, e).Value
'- Sprawdz ciag z kratek
CheckStr7 = Format(N1, "00") & " - " & Format(N2, "00") & " - " & Format(N3, "00") & " - " & Format(N4, "00") & " - " & Format(N5, "00")
CheckOtherRows5
If Counter > 1 Then
TempSheet.Cells(ToRow, 7).Value = "'" & CheckStr7
TempSheet.Cells(ToRow, 8).Value = Counter
ToSheet.Cells(ToRow, 16).Value = N1
ToSheet.Cells(ToRow, 17).Value = N2
ToSheet.Cells(ToRow, 18).Value = N3
ToSheet.Cells(ToRow, 19).Value = N4
ToSheet.Cells(ToRow, 20).Value = N5
ToSheet.Cells(ToRow, 21).Value = Counter
ToRow = ToRow + 1
End If
Next
Next
Next
Next
Next
Next
'-- sort results
Sort1
Sort2
Sort3
Sort4
MsgBox ("Done.")
Application.StatusBar = False
End Sub
'-----------------------------------------------------------------
Sub CheckOtherRows2()
'- check previous results for duplicate set
Set FoundCell = TempSheet.Columns(1).Find(what:=CheckStr1, lookat:=xlPart)
'- Not found - then look for matches in following rows
If FoundCell Is Nothing Then
Counter = 1
For rw = Fromrow + 1 To LastRow
For x = 2 To 6
N1a = FromSheet.Cells(rw, x).Value
For y = x + 1 To 6
N2a = FromSheet.Cells(rw, y).Value
CheckStr2 = Format(N1a, "00") & " - " & Format(N2a, "00")
'- match found - increment counter
If CheckStr1 = CheckStr2 Then
Counter = Counter + 1
End If
Next
Next
Next
End If
End Sub
'=== copy to here =================================================
'-----------------------------------------------------------------
Sub CheckOtherRows3()
'- check previous results for duplicate set
Set FoundCell = TempSheet.Columns(1).Find(what:=CheckStr3, lookat:=xlPart)
'- Not found - then look for matches in following rows
If FoundCell Is Nothing Then
Counter = 1
For rw = Fromrow + 1 To LastRow
For x = 2 To 6
N1a = FromSheet.Cells(rw, x).Value
For y = x + 1 To 6
N2a = FromSheet.Cells(rw, y).Value
For Z = y + 1 To 6
N3a = FromSheet.Cells(rw, Z).Value
CheckStr4 = Format(N1a, "00") & " - " & Format(N2a, "00") & " - " & Format(N3a, "00")
'- match found - increment counter
If CheckStr3 = CheckStr4 Then
Counter = Counter + 1
End If
Next
Next
Next
Next
End If
End Sub
'=== copy to here =================================================
Sub CheckOtherRows4()
'- check previous results for duplicate set
Set FoundCell = TempSheet.Columns(1).Find(what:=CheckStr5, lookat:=xlPart)
'- Not found - then look for matches in following rows
If FoundCell Is Nothing Then
Counter = 1
For rw = Fromrow + 1 To LastRow
For x = 2 To 6
N1a = FromSheet.Cells(rw, x).Value
For y = x + 1 To 6
N2a = FromSheet.Cells(rw, y).Value
For Z = y + 1 To 6
N3a = FromSheet.Cells(rw, Z).Value
For S = Z + 1 To 6
N4a = FromSheet.Cells(rw, S).Value
CheckStr6 = Format(N1a, "00") & " - " & Format(N2a, "00") & " - " & Format(N3a, "00") & " - " & Format(N4a, "00")
'- match found - increment counter
If CheckStr5 = CheckStr6 Then
Counter = Counter + 1
End If
Next
Next
Next
Next
Next
End If
End Sub
'=== copy to here =================================================
Sub CheckOtherRows5()
'- check previous results for duplicate set
Set FoundCell = TempSheet.Columns(1).Find(what:=CheckStr7, lookat:=xlPart)
'- Not found - then look for matches in following rows
If FoundCell Is Nothing Then
Counter = 1
For rw = Fromrow + 1 To LastRow
For x = 2 To 6
N1a = FromSheet.Cells(rw, x).Value
For y = x + 1 To 6
N2a = FromSheet.Cells(rw, y).Value
For Z = y + 1 To 6
N3a = FromSheet.Cells(rw, Z).Value
For S = Z + 1 To 6
N4a = FromSheet.Cells(rw, S).Value
For q = S + 1 To 6
N5a = FromSheet.Cells(rw, q).Value
CheckStr8 = Format(N1a, "00") & " - " & Format(N2a, "00") & " - " & Format(N3a, "00") & " - " & Format(N4a, "00") & " - " & Format(N5a, "00")
'- match found - increment counter
If CheckStr7 = CheckStr8 Then
Counter = Counter + 1
End If
Next
Next
Next
Next
Next
Next
End If
End Sub
'=== copy to here =================================================
Sub Sort1()
ToSheet.UsedRange.Columns("A:C").Sort Key1:=Range("C1"), Key2:=Range("A1:B1"), Order1:=xlDescending, Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
Sub Sort2()
ToSheet.UsedRange.Columns("E:H").Sort Key1:=Range("H1"), Key2:=Range("E1:F1:G1"), Order1:=xlDescending, Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
Sub Sort3()
ToSheet.UsedRange.Columns("I:M").Sort Key1:=Range("M1"), Key2:=Range("I1:J1:K1:L1"), Order1:=xlDescending, Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
Sub Sort4()
ToSheet.UsedRange.Columns("N:S").Sort Key1:=Range("S1"), Key2:=Range("N1:O1:P1:Q1:R1"), Order1:=xlDescending, Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub