Right I've it sorted using a combination of code from here and google. Huge thanks to AB33 for the majority of the code, specifically that part I couldn't work out. This code now is fully automatic. If I select anything from the drop down list it updates cell B1 which in turn then calls the consolidation function. Inside that it clears the sheet excluding the headings, adds back in the relevant data, then adds borders and sizes the columns correctly.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:B1")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "You have changed supplier to " & Range("A1")
Call ConsolidateSheets1
End If
End Sub
Sub ConsolidateSheets1()
Dim ms As Worksheet, ws As Worksheet, LR As Long, i As Long, NR&
Dim ss As String
ss = Range("B1")
ss = ss + "*"
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
On Error Resume Next
If Not Evaluate("ISREF(COUNT!A1)") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "COUNT"
Else
Set ms = Sheets("COUNT")
Sheets("COUNT").Range("A6:H" & Rows.Count).ClearContents
Call Borders
End If
For Each ws In ThisWorkbook.Sheets
With ws
If ws.Name <> "COUNT" And ws.Name <> "TV COUNT" And ws.Name <> "COMBI TV COUNT" Then
LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
For i = 5 To LR
If Trim(.Cells(i, 3).Value) Like ss Then
.Cells(i, 1).Resize(, 4).Copy ms.Cells(Rows.Count, "B").End(xlUp).Offset(1).Resize(, 4)
Rng = .Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - 1
ms.Cells(Rows.Count, 1).End(xlUp).Offset(1) = ws.Name
End If
Next i
End If
End With
Next ws
With ms
.Cells.Columns.EntireColumn.AutoFit
End With
Application.CutCopyMode = 0
Application.ScreenUpdating = 1
Application.DisplayAlerts = 1
Call SetColumnWidth
End Sub
Sub Borders()
Dim iLoop As Integer
With Range("A1:H1000")
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
For iLoop = 7 To 12
With .Borders(iLoop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Next
End With
End Sub
Sub SetColumnWidth()
Columns("A").ColumnWidth = 27.86
Columns("B").ColumnWidth = 13.57
Columns("C").ColumnWidth = 42.14
Columns("D:M").ColumnWidth = 10.14
End Sub
Bookmarks