This should match your actual layout:
Option Explicit
Sub TitleAnalysisLive()
Dim lLR1 As Long
Dim lLR2 As Long
Dim ws1 As Worksheet: Set ws1 = Sheets("Alla Projekt med Case")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Application.ScreenUpdating = False
' Determine last row on Alla Projekt med Case
With ws1
lLR1 = .Range("B" & .Rows.Count).End(xlUp).Row
End With
' Set up Sheet ws2
With ws2
' Remove old data
.Cells.Clear
' Advanced Filter unique Title entries
ws1.Columns("B:B").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=.Range("A1"), _
Unique:=True
' Determine last row on ws2
lLR2 = .Range("A" & .Rows.Count).End(xlUp).Row
' Create headings
.Range("A1:K1") = Split("Title|Entries|Idésökning|Arkiv|Projekt|LUAB|0|1|2|3|4", "|")
' Count entries for each Title
.Range("B2:B" & lLR2).FormulaR1C1 = _
"=COUNTIF('" & ws1.Name & "'!C,RC1)"
' Count ideas/archives/projects/company for each Title
.Range("C2:F" & lLR2).FormulaR1C1 = _
"=SUMPRODUCT(('" & ws1.Name & "'!R2C2:R" & lLR1 & _
"C2=RC1)*('" & ws1.Name & "'!R2C5:R" & lLR1 & _
"C5=R1C))"
' Count archive breakdown for each Title
.Range("G2:K" & lLR2).FormulaR1C1 = _
"=IF(RC4=0,"""",SUMPRODUCT(('" & ws1.Name & "'!R2C2:R" & lLR1 & _
"C2=RC1)*('" & ws1.Name & "'!R2C5:R" & lLR1 & _
"C5=""Arkiv"")*('" & ws1.Name & "'!R2C6:R" & lLR1 & _
"C6=--R1C)))"
' Format headings bold
With .Range("A1:K1")
.Font.Bold = True
End With
' Format all cells Centre
With .Range("A1:K" & lLR2)
.HorizontalAlignment = xlCenter
With .Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' Copy/PasteSpecial - convert formulae to values
'.Copy
'.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End With
End With
ws2.Select
Range("A1").Select
With ws2.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.SetRange Range("A2:K" & lLR2)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
Regards
Bookmarks