Makes much more sense, yes.
Ok, cell A1 must have the word "Title" on it before this macro will create the OUTPUT sheet. Make sure that data sheet is onscreen. Data must be in the two-column format demonstrated in your last workbook.
I've also adjusted the output, row/column intersection where the same name appears will only show values if they are the sole author of one or more publications, the table as a whole represents:
1) Number of time row/column intersecting authors co-authored publications
2) Number of times an author was the sole author of a publication. (See Miller, Lisa A. as an example)
The macro is CreateRelationalAuthorTable and goes in a standard code module.
Option Explicit
Sub CreateRelationalAuthorTable()
'Jerry Beaucaire 2/19/2013
'Creates a table of co-authorship
Dim LR As Long, wsOUT As Worksheet
With ActiveSheet
If .[A1] <> "Title" Then 'check cell A1 to make sure correct
MsgBox "Data sheet must be onscreen." 'sheet is onscreen before proceeding
Exit Sub
End If
Application.ScreenUpdating = False 'speed up execution
LR = .Range("A" & .Rows.Count).End(xlUp).Row 'last row with data
'create a key column w/all names together
.Range("C2:C" & LR).FormulaR1C1 = "=IF(RC1=R[-1]C1, R[-1]C3&RC2, RC2)"
.Range("D2:D" & LR).FormulaR1C1 = "=IF(RC1=R[1]C1, """", RC3)"
.Range("D1") = "Key"
.Columns("D:D").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("E1"), Unique:=True
.Columns("C:D").Delete Shift:=xlToLeft
'Get unique list of authors
.Columns("B:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("F1"), Unique:=True
LR = .Range("F" & .Rows.Count).End(xlUp).Row
.Range("F2.F" & LR).Copy 'put unique list across top of table, too
.Range("G1").PasteSpecial Paste:=xlPasteAll, Transpose:=True
With .Range("G1").CurrentRegion 'use key column and sum relations
.Offset(1, 1).FormulaR1C1 = "=IF(RC6=R1C, COUNTIF(R2C3:R" & LR & "C3,RC6), SUMPRODUCT(--ISNUMBER(SEARCH(RC6, R2C3:R" & LR & "C3)), --ISNUMBER(SEARCH(R1C, R2C3:R" & LR & "C3))))"
.Offset(1, 1).Value = .Offset(1, 1).Value 'remove formula, leave values behind
If Evaluate("ISREF(Output!A1)") Then 'create or reset the OUTPUT sheet
Sheets("Output").Cells.Clear
Else
Sheets.Add.Name = "Output"
Range("B2").Select
ActiveWindow.FreezePanes = True
End If
Set wsOUT = Sheets("Output")
.Copy 'copy the created table to the OUTPUT sheet
wsOUT.Range("A1").PasteSpecial xlPasteValues
.CurrentRegion.Clear 'clear the table from original sheet
End With
.Range("C:C").Clear 'clear the key column
End With
With wsOUT 'format the new OUTPUT table
.Activate
.Columns("A:A").Font.Bold = True
.Columns("A:A").ColumnWidth = 100
.Columns("A:A").EntireColumn.AutoFit
.Rows(1).RowHeight = 200
With Range("B1", Range("B1").End(xlToRight))
.VerticalAlignment = xlBottom
.Orientation = 90
.Font.Bold = True
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
End With
Application.ScreenUpdating = True 'return to normal speed
End Sub
Bookmarks