Validating Project Information – SplitSheet and SplitBook Functions
Page 1 of 2
SplitSheet and SplitBook Functions
1 SplitSheet Function
Once gaps were identified and missing documents or new revisions updated on both
systems; the data needed to be collated accordingly for reporting. When reporting to
different recipients that were interested only in certain parts of data, it was necessary to
split the data. Document owners were interested in status of their documents only;
therefore data was split by owner.
VBA Code ‘AddSheets()’ (Figure 1) creates multiple worksheets by values listed in one
column (i.e. ‘Owners’ in columns A of both worksheets). It splits the data of one master
worksheet into separate worksheets per document owner (values of first column in this
example) into multiple worksheets without having to manually sort it and copy-paste it from
one worksheet to another.It also keeps the master worksheet for further editing or filtering
if needed.
To split the master worksheet into multiple worksheets by values of first column:
1. Press Alt+F11 to open Visual Basic Editor (VBE);
2. On the Top Menu Select Insert ►Module from the context menu;
3. C
opy and paste VBA code to Code window;
4. Close VBE window;
5. Press Alt+F8 to open the ‘Macro’ dialog;
6. Select the ‘AddSheets()’ macro and click ‘Run’.
Figure 1 - ‘AddSheets()’ - VBA code for creating worksheets from selected cells
Change highlighted worksheet name (
BC) on VBA code to the title of worksheet that needs to
be split.
Dim s$, r
Application.ScreenUpdating = False
With Sheets("BC").Range("A1").CurrentRegion
.Parent.AutoFilterMode = False
For Each r In .Offset(1).Resize(.Rows.Count - 1).Columns(1).Value
If InStr(s, r) = 0 Then
If Not Evaluate("ISREF('" & r & "'!A1)") Then
Sheets.Add(after:=Sheets(Sheets.Count)).Name = r
Else
Sheets(r).UsedRange.ClearContents
End If
.AutoFilter 1, r
.Copy Sheets(r).Range("A1")
s = s & r
End If
Next
.AutoFilter
End With
Application.ScreenUpdating = True