Hi all
I wish to add a row when data changes in column 13 and colour it red (255), see code below. Any/all hints & help appreciated.
Regards Mark
[pre]
[/pre]
I wish to add a row when data changes in column 13 and colour it red (255), see code below. Any/all hints & help appreciated.
Regards Mark
[pre]
Code:
Sub SubtotalAndFormat()
' SubtotalAndFormat Macro
Dim aCell As Range, bCell As Range
Dim ExitLoop As Boolean
Dim iRow As Integer
Range("a1").Select
iRow = 2
Columns("B:B").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Add Key:=Range("B1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Mechanical").Sort
.SetRange Range("A1:P99646")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("M:M").Select
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Add Key:=Range("M1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Mechanical").Sort
.SetRange Range("A1:P99646")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("A:A").Select
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Mechanical").Sort.SortFields.Add Key:=Range("A1") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Mechanical").Sort
.SetRange Range("A1:P99646")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Sheets("Mechanical")
.Columns("A:P").Subtotal GroupBy:=13, Function:=xlCount, TotalList:=Array(1), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Set aCell = .Cells.Find(What:=" Count", LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
.Rows(aCell.Row).ClearContents
Do While ExitLoop = False
Set aCell = .Cells.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
.Rows(aCell.Row).ClearContents
Else
ExitLoop = True
End If
Loop
End If
.Cells.RemoveSubtotal
End With
End Sub
Sub Colour_Row()
'
' Colour_Row Macro
'
'
Range("A35:P35").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End Sub