Hi Mick,
I have been using the code that you have written for me and it has been working brilliantly, thanks so much for you time with it.
I have started encountering a small issue with the run numbering when there are more than 1 run that needs to be combined per machine and the runs are mixed in with other runs to be combined as it gives it the same number - see example below, is it possible to rectify it so they both have a different number? the combine code works fine it is just the number part.
<TABLE style="WIDTH: 702pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=933><COLGROUP><COL style="WIDTH: 88pt; mso-width-source: userset; mso-width-alt: 4278" width=117><COL style="WIDTH: 70pt; mso-width-source: userset; mso-width-alt: 3401" width=93><COL style="WIDTH: 65pt; mso-width-source: userset; mso-width-alt: 3145" width=86><COL style="WIDTH: 46pt; mso-width-source: userset; mso-width-alt: 2230" width=61><COL style="WIDTH: 39pt; mso-width-source: userset; mso-width-alt: 1901" width=52><COL style="WIDTH: 49pt; mso-width-source: userset; mso-width-alt: 2377" width=65><COL style="WIDTH: 43pt; mso-width-source: userset; mso-width-alt: 2084" width=57><COL style="WIDTH: 43pt; mso-width-source: userset; mso-width-alt: 2084" width=57><COL style="WIDTH: 176pt; mso-width-source: userset; mso-width-alt: 8557" width=234><COL style="WIDTH: 44pt; mso-width-source: userset; mso-width-alt: 2157" width=59><COL style="WIDTH: 39pt; mso-width-source: userset; mso-width-alt: 1901" width=52><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 88pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl71 height=20 width=117>
Single Set No 1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 70pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl64 width=93></TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: lime; WIDTH: 65pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl70 width=86>
1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 46pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl69 width=61>
125871</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 39pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl72 width=52>
06:46</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 49pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl72 width=65>
07:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 43pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73 width=57>
BSE</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 43pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl74 width=57>
333</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 176pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73 width=234>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 44pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73 width=59>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; WIDTH: 39pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl74 width=52>
0</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl75 height=20>
Single Set No 1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl64></TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: lime; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl70>
1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl76>
125864</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl77>
07:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl77>
14:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
GHY</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl79>
1224</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl79>
0</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl75 height=20>
Single Set No 1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl64></TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl69>
1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl76>
125986</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl77>
14:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl77>
16:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
GHY</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl79>
1163</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl78>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ff6699; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl79>
0</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl71 height=20>
Single Set No 1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl64></TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl69>
1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl69>
124785</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl72>
16:37</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl72>
16:52</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73>
BSE</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl74>
53</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl73>
Natural</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl74>
0</TD></TR></TBODY></TABLE>
Here is the lastest code for the macro
Code:
Sub CombineRest()
Dim rng As Range
Dim Dn As Range
Dim nRng As Range
Dim Tri As String
Dim Q As Variant
Dim k
Dim Rw As Range
Dim nnRng As Range
Dim colRng As Range
Dim ColRng2 As Range
Dim n As Long
Set rng = Range(Range("C7"), Range("C" & Rows.count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In rng
If Not UCase(Dn.Offset(, -1)) = "N" Then
Tri = Dn & Dn(, 5) & Dn(, 8) & Dn(, 9)
If Not .exists(Tri) Then
.Add Tri, Array(Dn, nRng)
Else
Q = .Item(Tri)
If Q(1) Is Nothing Then
Set Q(1) = Dn
Else
Set Q(1) = Union(Q(1), Dn)
End If
.Item(Tri) = Q
End If
End If
Next Dn
For Each k In .Keys
If Not .Item(k)(1) Is Nothing And .Item(k)(0).Offset(, 12) <= 1 Then
If Range("A2").Interior.ColorIndex = xlNone Then
If colRng Is Nothing Then
Set colRng = .Item(k)(1)
Else
Set colRng = Union(colRng, .Item(k)(1))
End If
If ColRng2 Is Nothing Then
Set ColRng2 = .Item(k)(0)
Else
Set ColRng2 = Union(ColRng2, .Item(k)(0))
End If
ElseIf Range("A2").Interior.ColorIndex = 6 Then
'''''''''''''''''
Dim uRng As Range, Du As Range, uTxt
For Tmix = 16 To 24
Set uRng = Union(.Item(k)(0).Offset(, Tmix), .Item(k)(1).Offset(, Tmix))
For Each Du In uRng
If InStr(uTxt, Du) = 0 Then
uTxt = uTxt & "," & Du
End If
Next Du
.Item(k)(0).Offset(, Tmix) = Mid(uTxt, 2)
uTxt = ""
Next Tmix
'''''''''''''''''''''''''''''
.Item(k)(0).Offset(, 5) = .Item(k)(0).Offset(, 5) + Application.Sum(.Item(k)(1).Offset(, 5))
.Item(k)(0).Offset(, 9) = .Item(k)(0).Offset(, 9) + Application.Sum(.Item(k)(1).Offset(, 9))
.Item(k)(0).Offset(, 14) = .Item(k)(0).Offset(, 14) + Application.Sum(.Item(k)(1).Offset(, 14))
If nnRng Is Nothing Then
Set nnRng = .Item(k)(1)
Else
Set nnRng = Union(nnRng, .Item(k)(1))
End If
End If
End If
Next k
If Not colRng Is Nothing Then
For n = 1 To colRng.Areas.count
colRng.Areas(n).Offset(, -2) = "Single Set No " & n
ColRng2.Areas(n).Offset(, -2) = "Single Set No " & n
Next n
colRng.Interior.ColorIndex = 35
Range("A2").Interior.ColorIndex = 6
ElseIf colRng Is Nothing Then
Range("A2").Interior.ColorIndex = xlNone
End If
If Not ColRng2 Is Nothing Then
ColRng2.Interior.ColorIndex = 4
'ColRng2.Offset(, -1) = "Combined"
End If
If Not nnRng Is Nothing Then
Range("A2").Interior.ColorIndex = xlNone
With nnRng
.ClearContents
.EntireRow.Hidden = True
End With
End If
End With
rng.Offset(, 16).Resize(, 9).Columns.AutoFit
Set rng = Nothing
Set nRng = Nothing
Set nnRng = Nothing
Set colRng = Nothing
Set ColRng2 = Nothing
End Sub
Regards Damian