Macros
General Macros at Work
VBA: General Module - Work
Public MidSub As Integer
Sub Styles2()
Call TurnStuffOff
Set Bk1 = ActiveWorkbook
x = Bk1.Sheets.Count
i = 1
For Each Sheet In Bk1.Sheets
If i > 1 Then Sheet.Move After:=Bk2.Sheets(i - 1)
If i = 1 Then Sheet.Move: Set Bk2 = ActiveWorkbook
If i <> x Then Bk1.Activate: i = i + 1
Next Sheet
Call TurnStuffOn
End Sub
Sub Auto_Fit()
If MidSub <> vbYes Then Call TurnStuffOff
For Each Cell In Selection
If Cell.Value = "" Then GoTo Next_Cell
If Cell.Address = Cell.MergeArea.Address Then GoTo Next_Cell
Set AutoFitRng = Range(Cell.MergeArea.Address)
With AutoFitRng
.MergeCells = False
CWidth = .Cells(1).ColumnWidth
MergeWidth = 0
For Each cM In AutoFitRng
cM.WrapText = True
MergeWidth = cM.ColumnWidth + MergeWidth
Next
'Small adjustment to temporary width
MergeWidth = MergeWidth + AutoFitRng.Cells.Count * 0.66
.Cells(1).ColumnWidth = Application.Min(MergeWidth, 255)
.EntireRow.AutoFit
NewRowHt = .RowHeight
.Cells(1).ColumnWidth = CWidth
.MergeCells = True
.RowHeight = NewRowHt
End With
Next_Cell:
Next Cell
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Barclays_Reformat()
Call TurnStuffOff
wbName = ActiveWorkbook.Path & "\" & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
On Error GoTo NxtS
For Each Style In ActiveWorkbook.Styles
If Style Like "*Heading*" Or Style Like "*Total*" Or Style Like "*Title*" Then GoTo NxtS
Style.Font.Name = "Aptos Narrow"
Style.Font.Size = 8
NxtS:
Next Style
ActiveWorkbook.Styles("Comma").NumberFormat = "_-#,##0.00_-;_-(#,##0.00);_-""-""??_);@"
Range("A2,A4:A8,A10:A12,A18:A21").EntireRow.Delete
d1 = Format(Mid(Range("A3"), InStr(Range("A3"), "From:") + 6, 10), "D MMM YYYY")
d2 = Format(Mid(Range("A3"), InStr(Range("A3"), "To:") + 4, 10), "D MMM YYYY")
If InStr(d2, Right(d1, 4)) Then d1 = Left(d1, Len(d1) - 5)
Range("A2").FormulaR1C1 = Replace(Range("B6").Value, "AK", "ARK") & " - ACCOUNT STATEMENT"
Range("A3").FormulaR1C1 = "For the period from " & d1 & " to " & d2
Range("B7").Resize(2, 1).Cut
Range("A5").Insert Shift:=xlToRight
Range("A7").Resize(2, 1).Cut Range("C5")
Range("A5") = "Sort Code"
Range("5:6").WrapText = False
Range("7:8").Delete
Range("D5:Z6").Delete xlToLeft
Range("A:A").ColumnWidth = 10
Range("B:B").ColumnWidth = 30
Range("C:F").ColumnWidth = 15
yMax = Range("F10000").End(xlUp).Row
Cells.WrapText = False
Cells.EntireRow.AutoFit
Cells.Font.Name = "Aptos Narrow"
Cells.Font.Size = 8
Cells.Font.Superscript = False
Range("A1:A3").Select
With Selection
.Font.Size = 10
.Font.Bold = True
End With
MidSub = vbYes: Call Add_UPPER: MidSub = vbNo
Range(yMax + 1 & ":10000").Delete
Range("A8:A" & yMax).HorizontalAlignment = xlCenter
Range("A9:C" & yMax).WrapText = True
Range("D9:F" & yMax).Style = "Comma"
Range("A9:F" & yMax).VerticalAlignment = xlTop
For Each Cell In Range("D9:D" & yMax).SpecialCells(xlCellTypeConstants)
Cell.Value = -Cell.Value
Next Cell
Range("A8").FormulaR1C1 = "GL Date"
Range("B8").FormulaR1C1 = "Description"
Range("C8").FormulaR1C1 = "Type"
With Range("A8:F8")
.Font.Size = 9
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
End With
Range("A1").Select
ActiveWorkbook.SaveAs wbName, xlWorkbookDefault
Call TurnStuffOn
End Sub
Sub CheckLinks()
For Each Cell In Selection
If Cell.Hyperlinks.Count > 1 Then Cell.Select: MsgBox "Cell contains more than one hyperlink!", vbCritical + vbOKOnly, "Error:"
If Cell.Hyperlinks.Count > 0 Then
Debug.Print Cell.Hyperlinks(1).Address
If Dir(Cell.Hyperlinks(1).Address, vbDirectory) = "" Then
Cell.Select
MsgBox "Check hyperlink!", vbOKOnly, "Error:"
Exit Sub
End If
End If
Next Cell
MsgBox "All hyperlinks are valid!", vbOKOnly, "Success!"
End Sub
Sub Clear_Redundant_Area()
'This macro removes the unused saved areas through the sheet or entire workbook (based on user input).
Continue = InputBox("This macro is used to delete the redundant areas at the bottom of each sheet. Would you like to perform this for the entire workbook or just the current sheet?" _
& vbNewLine & vbNewLine & "Type 'S' for the Sheet and 'W' for the workbook.", "Continue?")
If Continue = "s" Then Continue = "S"
If Continue = "w" Then Continue = "W"
If Continue <> "S" And Continue <> "W" Then Exit Sub
If Continue = "S" Then GoTo SPerform
If MidSub <> vbYes Then Call TurnStuffOff
Set Rtn = ActiveSheet
Hide = vbNo
For Each Sheet In ActiveWorkbook.Sheets
If Sheet.Visible = False Then Sheet.Visible = True: Hide = vbYes
Sheet.Activate
'Set the "Expected" max row & column by cycling through each cell and obtaining the maximum number for each variable.
MaxColE = 1
MaxRowE = 1
WConstants:
On Error GoTo -1
On Error GoTo WFormulas
For Each Cell In ActiveSheet.UsedRange.SpecialCells(xlConstants)
If Cell.Column > MaxColE Then MaxColE = Cell.Column
If Cell.Row > MaxRowE Then MaxRowE = Cell.Row
Next Cell
WFormulas:
On Error GoTo -1
On Error GoTo WLastCell
For Each Cell In ActiveSheet.UsedRange.SpecialCells(xlFormulas)
If Cell.Column > MaxColE Then MaxColE = Cell.Column
If Cell.Row > MaxRowE Then MaxRowE = Cell.Row
Next Cell
WLastCell:
'Set the "Current" max row and column by looking at the last cell in the sheet.
MaxColC = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Column
MaxRowC = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Row
'Remove the difference between expectation & current areas.
If MaxColC > MaxColE And MaxColE <> MaxColC Then Range(Cells(1, MaxColE + 1), Cells(1, MaxColC)).EntireColumn.Delete
If MaxRowC > MaxRowE And MaxRowE <> MaxRowC Then Range(Cells(MaxRowE + 1, 1), Cells(MaxRowC, 1)).EntireRow.Delete
If Hide = vbYes Then Sheet.Visible = False: Hide = vbNo
Next Sheet
Rtn.Activate
ActiveWorkbook.Save
If MidSub <> vbYes Then Call TurnStuffOn
Exit Sub
SPerform:
MaxColE = 1
MaxRowE = 1
SConstants:
On Error GoTo -1
On Error GoTo SFormulas
For Each Cell In ActiveSheet.UsedRange.SpecialCells(xlConstants)
If Cell.Column > MaxColE Then MaxColE = Cell.Column
If Cell.Row > MaxRowE Then MaxRowE = Cell.Row
Next Cell
SFormulas:
On Error GoTo -1
On Error GoTo SLastCell
For Each Cell In ActiveSheet.UsedRange.SpecialCells(xlFormulas)
If Cell.Column > MaxColE Then MaxColE = Cell.Column
If Cell.Row > MaxRowE Then MaxRowE = Cell.Row
Next Cell
SLastCell:
'Set the "Current" max row and column by looking at the last cell in the sheet.
MaxColC = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Column
MaxRowC = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Row
'Remove the difference between expectation & current areas.
If MaxColC > MaxColE And MaxColE <> MaxColC Then Range(Cells(1, MaxColE + 1), Cells(1, MaxColC)).EntireColumn.Delete
If MaxRowC > MaxRowE And MaxRowE <> MaxRowC Then Range(Cells(MaxRowE + 1, 1), Cells(MaxRowC, 1)).EntireRow.Delete
ActiveWorkbook.Save
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub ClearConditionalFormats()
Cells.FormatConditions.Delete
End Sub
Sub Count_Styles()
Dim i As Long
For Each Style In ActiveWorkbook.Styles
i = i + 1
Next Style
MsgBox i & " styles remain in the document."
End Sub
Sub Hyperlinks_Del()
Dim Cell As Range, HL As Hyperlink
Continue = MsgBox("This macro will delete all hyperlinks in selected cells. Would you like to continue?", vbYesNo + vbInformation, "Continue?")
If Continue = vbNo Then Exit Sub
Call TurnStuffOff
For Each Cell In Selection
For Each HL In Cell.Hyperlinks
HL.Delete
Next HL
Next Cell
Call TurnStuffOn
End Sub
Sub Hyperlinks_Fix()
Continue = MsgBox("This macro will replace text within hyperlinks in selected cells. Would you like to continue?", vbYesNo + vbInformation, "Continue?")
If Continue = vbNo Then Exit Sub
On Error Resume Next
Call TurnStuffOff
StdChg = MsgBox("Would you like to make some standard replacements of date formats?", vbYesNo + vbQuestion, "Standard Replacements:")
If StdChg = vbYes Then
For Each HL In Selection.Hyperlinks
HL.Address = Replace(HL.Address, "../../../../", "https://thearkenstonegroup.sharepoint.com/")
' hl.Address = Replace(hl.Address, "1. January", "01 Jan")
' hl.Address = Replace(hl.Address, "2. February", "02 Feb")
' hl.Address = Replace(hl.Address, "3. March", "03 Mar")
' hl.Address = Replace(hl.Address, "4. April", "04 Apr")
' hl.Address = Replace(hl.Address, "5. May", "05 May")
' hl.Address = Replace(hl.Address, "6. June", "06 Jun")
' hl.Address = Replace(hl.Address, "7. July", "07 Jul")
' hl.Address = Replace(hl.Address, "8. August", "08 Aug")
' hl.Address = Replace(hl.Address, "9. September", "09 Sep")
' hl.Address = Replace(hl.Address, "01. January", "01 Jan")
' hl.Address = Replace(hl.Address, "02. February", "02 Feb")
' hl.Address = Replace(hl.Address, "03. March", "03 Mar")
' hl.Address = Replace(hl.Address, "04. April", "04 Apr")
' hl.Address = Replace(hl.Address, "05. May", "05 May")
' hl.Address = Replace(hl.Address, "06. June", "06 Jun")
' hl.Address = Replace(hl.Address, "07. July", "07 Jul")
' hl.Address = Replace(hl.Address, "08. August", "08 Aug")
' hl.Address = Replace(hl.Address, "09. September", "09 Sep")
' hl.Address = Replace(hl.Address, "10. October", "10 Oct")
' hl.Address = Replace(hl.Address, "11. November", "11 Nov")
' hl.Address = Replace(hl.Address, "12. December", "12 Dec")
' hl.Address = Replace(hl.Address, "01 January", "01 Jan")
' hl.Address = Replace(hl.Address, "02 February", "02 Feb")
' hl.Address = Replace(hl.Address, "03 March", "03 Mar")
' hl.Address = Replace(hl.Address, "04 April", "04 Apr")
' hl.Address = Replace(hl.Address, "05 May", "05 May")
' hl.Address = Replace(hl.Address, "06 June", "06 Jun")
' hl.Address = Replace(hl.Address, "07 July", "07 Jul")
' hl.Address = Replace(hl.Address, "08 August", "08 Aug")
' hl.Address = Replace(hl.Address, "09 September", "09 Sep")
' hl.Address = Replace(hl.Address, "10 October", "10 Oct")
' hl.Address = Replace(hl.Address, "11 November", "11 Nov")
' hl.Address = Replace(hl.Address, "12 December", "12 Dec")
' hl.Address = Replace(hl.Address, "\202301", "\2023.01.")
' hl.Address = Replace(hl.Address, "\202302", "\2023.02.")
' hl.Address = Replace(hl.Address, "\202303", "\2023.03.")
' hl.Address = Replace(hl.Address, "\202304", "\2023.04.")
' hl.Address = Replace(hl.Address, "\202305", "\2023.05.")
' hl.Address = Replace(hl.Address, "\202306", "\2023.06.")
' hl.Address = Replace(hl.Address, "\202307", "\2023.07.")
' hl.Address = Replace(hl.Address, "\202308", "\2023.08.")
' hl.Address = Replace(hl.Address, "\202309", "\2023.09.")
' hl.Address = Replace(hl.Address, "\202310", "\2023.10.")
' hl.Address = Replace(hl.Address, "\202311", "\2023.11.")
' hl.Address = Replace(hl.Address, "\202312", "\2023.12.")
Next HL
End If
' NonStdChg = MsgBox("Would you like to make some non-standard replacements of other text?", vbYesNo + vbQuestion, "Non-Standard Replacements:")
' If NonStdChg = vbYes Then
' sOld = InputBox("What would you like to replace in the old hyperlinks?", "Replace What:")
' sNew = InputBox("What would you like to replace that text with?", "Replacement:")
'
' On Error Resume Next
' For Each hl In Selection.Hyperlinks
'' Debug.Print hl.Address
' hl.Address = Replace(hl.Address, sOld, sNew)
'' Debug.Print hl.Address
' Next hl
' End If
Call TurnStuffOn
End Sub
Sub Footnotes_Std()
Dim FN As String
Dim Rtrn As Integer
Set Rtn = ActiveSheet
If MidSub <> vbYes Then Call TurnStuffOff
W_S = InputBox("Would you like to run the macro on the whole workbook (W) or just the selected sheets (S)?", "Workbook or Sheet?")
If W_S = "" Then Exit Sub
If W_S = "w" Or W_S = "s" Then W_S = UCase(W_S)
If W_S <> "W" And W_S <> "S" Then MsgBox "Please enter either W or S when asked if you would like to run the macro on the whole workbook or just the selected sheets. Nothing happened.", vbCritical, "Try again:": Exit Sub
If W_S = "W" Then Set xSh = ActiveWorkbook.Sheets Else Set xSh = ActiveWindow.SelectedSheets
For Each Sheet In xSh
On Error GoTo -1
On Error GoTo Next_Sheet
Sheet.Select
FN = Cells.Find("The notes on page", Cells(1, 1), xlValues, xlPart).Address(0, 0)
RowFN = Range(FN).Row
RowP = Range(FN).End(xlUp).Row + 1
Rows(RowP & ":" & RowFN - 1).AutoFit
If ActiveSheet.HPageBreaks.Count > 0 Then
Do Until ActiveSheet.HPageBreaks.Count = 0
Rows(RowFN - 1).EntireRow.Delete
RowFN = RowFN - 1
Loop
End If
FN = Cells.Find("The notes on page").Address(0, 0)
If ActiveSheet.HPageBreaks.Count = 0 Then
Do Until ActiveSheet.HPageBreaks.Count > 0
Range(FN).Offset(-1, 0).EntireRow.Insert
Loop
FN = Cells.Find("The notes on page").Address(0, 0)
Range(FN).Offset(-1, 0).EntireRow.Delete
FN = Cells.Find("The notes on page").Address(0, 0)
Do Until ActiveSheet.HPageBreaks.Count > 0
Height_C = Range(FN).Offset(-1, 0).RowHeight
Range(FN).Offset(-1, 0).RowHeight = Height_C + 0.75
Loop
Range(FN).Offset(-1, 0).RowHeight = Height_C
End If
Next_Sheet:
Next Sheet
Rtn.Select
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Footnotes_Selection()
Dim FN As String
Dim Rtrn As Integer
Continue = MsgBox("This macro will align the current cell with the bottom of the page. Are you sure you wish to continue?", vbQuestion + vbYesNo, "Continue?")
If Continue = vbNo Then Exit Sub
On Error GoTo -1
On Error GoTo End_Sub
FN = Selection.Address(0, 0)
RowFN = Range(FN).Row
RowP = Range(FN).End(xlUp).Row + 1
Rows(RowP + 1 & ":" & RowFN - 1).AutoFit
Do Until Range(FN).EntireRow.PageBreak <> -4142
Range(FN).Offset(-1, 0).EntireRow.Insert
FN = Range(FN).Offset(1, 0).Address(0, 0)
Loop
Range(FN).Offset(-1, 0).EntireRow.Delete
FN = Range(FN).Offset(-1, 0).Address(0, 0)
Do Until Range(FN).EntireRow.PageBreak <> -4142
Height_C = Range(FN).Offset(-1, 0).RowHeight
Range(FN).Offset(-1, 0).RowHeight = Height_C + 0.75
Loop
Range(FN).Offset(-1, 0).RowHeight = Height_C
End_Sub:
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Ideal_Comma()
'This macro changes the Comma style to that preferred for the presentation of your excel workings.
dps = InputBox("How many decimal places would you like the Comma style to contain?" _
& vbNewLine & vbNewLine & "Note: Please input in '0.00' format.", "Decimal Places?")
If dps = "" Then Exit Sub
Idnt = MsgBox("Would you like force the alignment to the right of the cell?", vbYesNo, "Force Right?")
Rd = MsgBox("Would you like negative figures to appear in red text?", vbYesNo, "Red Negatives?")
If Idnt = vbYes Then
If Rd = vbYes Then
ActiveWorkbook.Styles("Comma").NumberFormat = "_-* #,##" & dps & "_);[RED]_-* (#,##" & dps & ");_-* ""-""??_);_-@_)"
Else
ActiveWorkbook.Styles("Comma").NumberFormat = "_-* #,##" & dps & "_);_-* (#,##" & dps & ");_-* ""-""??_);_-@_)"
End If
Else
If Rd = vbYes Then
ActiveWorkbook.Styles("Comma").NumberFormat = "_-#,##" & dps & "_);[RED]_-(#,##" & dps & ");_-??""-""??_);_-@_)"
Else
ActiveWorkbook.Styles("Comma").NumberFormat = "_-#,##" & dps & "_);_-(#,##" & dps & ");_-??""-""??_);_-@_)"
End If
End If
ReStyle = MsgBox("Would you like to change the numbers within this workbook to the updated comma style?", vbQuestion + vbYesNo, "ReStyle?")
If ReStyle = vbYes Then
If MidSub <> vbYes Then Call TurnStuffOff
On Error Resume Next
For Each Sheet In ActiveWorkbook.Sheets
If Sheet.Visible = False Then Sheet.Visible = True: Hide = vbYes
Sheet.Activate
For Each Cell In Cells.SpecialCells(xlCellTypeConstants, 1)
If Cell.Style <> "Percent" And Cell.NumberFormat <> "m/d/yyyy" Then Cell.Style = "Comma"
Next Cell
For Each Cell In Cells.SpecialCells(xlCellTypeFormulas, 1)
If Cell.Style <> "Percent" And Cell.NumberFormat <> "m/d/yyyy" Then Cell.Style = "Comma"
Next Cell
If Hide = vbYes Then Sheet.Visible = False
Hide = vbNo
Next Sheet
If MidSub <> vbYes Then Call TurnStuffOn
End If
End Sub
Sub Ideal_Percent()
'This macro changes the Percent style to that preferred for the presentation of your excel workings.
Begin:
dps = InputBox("How many decimal places would you like the Percent style to contain?" _
& vbNewLine & vbNewLine & "Note: Please input in '0.00' format.", "Decimal Places?")
If dps = "" Then Exit Sub
On Error GoTo -1
On Error GoTo Leave
x = Int(dps)
Idnt = MsgBox("Would you like force the alignment to the right of the cell?", vbYesNo, "Force Right?")
Rd = MsgBox("Would you like negative figures to appear in red text?", vbYesNo, "Red Negatives?")
If Idnt = vbYes Then
ActiveWorkbook.Styles("Percent").NumberFormat = "_-* #,##" & dps & "%_-;_-* (#,##" & dps & "%);_-* ""-""??%_-;_-@_-"
If Rd = vbYes Then ActiveWorkbook.Styles("Percent").NumberFormat = "_-* #,##" & dps & "%_-;[RED]_-* (#,##" & dps & "%);_- ""-""??%_-;_-@_-"
Else
ActiveWorkbook.Styles("Percent").NumberFormat = "_- #,##" & dps & "%_-;_- (#,##" & dps & "%);_- ""-""??%_-;_-@_-"
If Rd = vbYes Then ActiveWorkbook.Styles("Percent").NumberFormat = "_- #,##" & dps & "%_-;[RED]_- (#,##" & dps & "%);_- ""-""??%_-;_-@_-"
End If
Exit Sub
Leave:
Retry = MsgBox("The style must be input in '0.00' format." & vbNewLine & vbNewLine & "Would you like to try again?", vbCritical + vbYesNo, "Retry?")
If Retry = vbYes Then GoTo Begin
End Sub
Sub Ideal_Tables()
'This macro creates table styles aligned with my preferred styling.
On Error Resume Next
ActiveWorkbook.TableStyles.Add ("Trove")
With ActiveWorkbook.TableStyles("Trove")
.ShowAsAvailableTableStyle = True
.ShowAsAvailablePivotTableStyle = True
.TableStyleElements(xlWholeTable).Borders.Weight = xlMedium
.TableStyleElements(xlHeaderRow).Font.FontStyle = "Bold"
.TableStyleElements(xlHeaderRow).Font.Color = vbWhite
.TableStyleElements(xlHeaderRow).Interior.Color = 6299648
.TableStyleElements(xlHeaderRow).Borders.Weight = xlMedium
.TableStyleElements(xlTotalRow).Font.FontStyle = "Bold"
.TableStyleElements(xlTotalRow).Font.Color = vbWhite
.TableStyleElements(xlTotalRow).Interior.Color = 6299648
.TableStyleElements(xlTotalRow).Borders.Weight = xlMedium
.TableStyleElements(xlSubtotalRow1).Font.FontStyle = "Bold"
.TableStyleElements(xlSubtotalRow1).Interior.ThemeColor = xlThemeColorAccent5
.TableStyleElements(xlSubtotalRow1).Interior.TintAndShade = 0.4
.TableStyleElements(xlSubtotalRow1).Borders.Weight = xlMedium
.TableStyleElements(xlSubtotalRow2).Font.FontStyle = "Bold"
.TableStyleElements(xlSubtotalRow2).Interior.ThemeColor = xlThemeColorAccent5
.TableStyleElements(xlSubtotalRow2).Interior.TintAndShade = 0.6
.TableStyleElements(xlSubtotalRow2).Borders.Weight = xlMedium
.TableStyleElements(xlSubtotalRow3).Font.FontStyle = "Bold"
.TableStyleElements(xlSubtotalRow3).Interior.ThemeColor = xlThemeColorAccent5
.TableStyleElements(xlSubtotalRow3).Interior.TintAndShade = 0.8
.TableStyleElements(xlSubtotalRow3).Borders.Weight = xlMedium
.TableStyleElements(xlPageFieldLabels).Font.FontStyle = "Bold"
.TableStyleElements(xlPageFieldLabels).Interior.Color = 15773696
.TableStyleElements(xlPageFieldLabels).Borders.ColorIndex = xlAutomatic
.TableStyleElements(xlPageFieldLabels).Borders.Weight = xlMedium
End With
End Sub
Sub GetC()
x = ActiveCell.Interior.Color
End Sub
Sub Indent_Selection()
Dim Cell As Range
Dim MrgRng As Range
Indent_No = InputBox("This macro will indent all of the text found within the selection. Please input the number of columns for indentation." _
& vbNewLine & vbNewLine & "NB: Do not run this on indented bullets as it will overwrite the bulleted text.")
If Indent_No = "" Or Indent_No = 0 Then Exit Sub
If MidSub <> vbYes Then Call TurnStuffOff
MidSub = vbYes
For Each Cell In Selection
If OldAdd = Cell.Address Then GoTo Next_Cell
If Cell.Value = "" Then GoTo Next_Cell
If Cell.Address = Cell.MergeArea.Address Then GoTo Next_Cell
x = Cell.MergeArea.Columns.Count
Cell.MergeCells = False
Cell.Cut Range(Cell.Offset(0, Indent_No).Address)
OldAdd = Cell.Address
Set MrgRng = Range(Cell.Address).Resize(1, x - Indent_No)
MrgRng.Select
MrgRng.MergeCells = True
Call Auto_Fit
Next_Cell:
Next Cell
MidSub = vbNo
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Notes_Depersonalise()
For Each Cell In Selection
On Error GoTo -1
On Error GoTo Skip
x = Replace(Cell.NoteText, "Bradley Galluzzi:" & Chr(10), "")
Cell.Comment.Delete
Cell.AddComment (x)
Cell.Comment.Shape.TextFrame.AutoSize = True
Skip:
Next Cell
End Sub
Sub Pivot_Cache_Count()
If ActiveWorkbook.PivotCaches.Count = 0 Then
MsgBox "There are no pivot caches in the active workbook.", vbOKOnly, "Cache Count"
Else
If ActiveWorkbook.PivotCaches.Count = 1 Then
MsgBox "There is " & ActiveWorkbook.PivotCaches.Count & " pivot cache in the active workbook.", vbOKOnly, "Cache Count"
Else
MsgBox "There are " & ActiveWorkbook.PivotCaches.Count & " pivot caches in the active workbook.", vbOKOnly, "Cache Count"
End If
End If
End Sub
Sub RebuildDefaultStyles()
'This macro removes all styles in the active workbook and rebuilds the default styles by merging them from a new workbook.
Dim MyBook As Workbook, tempBook As Workbook, CurStyle As Style, x As Long
If MidSub <> vbYes Then Call TurnStuffOff
Set MyBook = ActiveWorkbook 'Set MyBook to the active workbook.
x = 0: i = 0
'Delete all the styles in the workbook.
For Each CurStyle In MyBook.Styles
On Error GoTo -1: On Error GoTo Next_Style
x = x + 1
Select Case CurStyle.Name
'Do nothing, as these are the default styles.
Case "20% - Accent1", "20% - Accent2", _
"20% - Accent3", "20% - Accent4", "20% - Accent5", "20% - Accent6", _
"40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", _
"40% - Accent5", "40% - Accent6", "60% - Accent1", "60% - Accent2", _
"60% - Accent3", "60% - Accent4", "60% - Accent5", "60% - Accent6", _
"Accent1", "Accent2", "Accent3", "Accent4", "Accent5", "Accent6", _
"Bad", "Calculation", "Check Cell", "Comma", "Comma [0]", "Currency", _
"Currency [0]", "Explanatory Text", "Good", "Heading 1", "Heading 2", _
"Heading 3", "Heading 4", "Input", "Linked Cell", "Neutral", "Normal", _
"Note", "Output", "Percent", "Title", "Total", "Warning Text"
Case Else 'Delete the style.
CurStyle.Delete
i = i + 1
End Select
Next_Style:
Next CurStyle
Set tempBook = Workbooks.Add 'Open a new workbook.
MyBook.Styles.Merge Workbook:=tempBook 'Merge styles from the new workbook into the existing workbook.
tempBook.Close 'Close the new workbook.
If MidSub <> vbYes Then Call TurnStuffOn
MsgBox "Success! " & i & " out of " & x & " styles were deleted. " & x - i & " styles remain.", vbOKOnly, "Success!"
End Sub
Sub Re_Bullet_General()
Dim ToFix As New Collection
Dim Cell As Range
Dim MrgRng As Range
Continue = MsgBox("This macro will indent all of the bullets found within the activesheet. This is supposed to be used on the notes of financial statements." _
& vbNewLine & vbNewLine & "Would you like to proceed?", vbYesNo, "Continue?")
If Continue = vbNo Then Exit Sub
If MidSub <> vbYes Then Call TurnStuffOff
MidSub = vbYes
ToFix.Add ("A1")
Cells(1, 1).Select
Do Until Looped = vbYes
Cells.Find(What:="(?)*", After:=ActiveCell, LookIn:=xlFormulas2, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If ActiveCell.Address = ToFix(1) Then Exit Do
If ToFix(1) = "A1" Then ToFix.Remove 1
ToFix.Add (ActiveCell.Address)
Loop
For i = 1 To ToFix.Count
Set Cell = Range(ToFix(i))
If Cell.Address = Cell.MergeArea.Address Then GoTo Next_Cell
Cell.VerticalAlignment = xlTop
x = Cell.MergeArea.Columns.Count
Cell.MergeCells = False
Set MrgRng = Range(Cell.Address).Offset(0, 1).Resize(1, x - 1)
x = InStr(Cell.Value, " ")
Bullet = Left(Cell.Value, x - 1)
Txt = Right(Cell.Value, Len(Cell.Value) - x)
Cell.Value = Bullet
Cell.Copy
MrgRng.PasteSpecial Paste:=xlPasteFormats
MrgRng.MergeCells = True
MrgRng.Value = Txt
Call Auto_Fit
Next_Cell:
Next i
MidSub = vbNo
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Re_Bullet_Selection()
Dim Cell As Range
Dim MrgRng As Range
Bullet_Type = InputBox("This macro will indent all of the bullets found within the selection. Please define your bullet type followed by a space, e.g. ""- "".")
If Bullet_Type = "" Then Exit Sub
MidSub = vbYes
If MidSub <> vbYes Then Call TurnStuffOff
For Each Cell In Selection
If Not InStr(Cell.Value, Bullet_Type) > 0 Then GoTo Next_Cell
If Cell.Address = Cell.MergeArea.Address Then GoTo Next_Cell
Cell.VerticalAlignment = xlTop
x = Cell.MergeArea.Columns.Count
Cell.MergeCells = False
Set MrgRng = Range(Cell.Address).Offset(0, 1).Resize(1, x - 1)
x = InStr(Cell.Value, Bullet_Type)
Bullet = Application.Trim(Left(Cell.Value, x + 1))
Txt = Right(Cell.Value, Len(Cell.Value) - x - 1)
Cell.Value = Bullet
Cell.Copy
MrgRng.PasteSpecial Paste:=xlPasteFormats
MrgRng.MergeCells = True
MrgRng.Value = Application.Trim(Txt)
MrgRng.HorizontalAlignment = xlJustify
MrgRng.Font.Name = "Calibri"
Call Auto_Fit
Next_Cell:
Next Cell
MidSub = vbNo
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub RescopeNamedRangesToWorkbook()
Dim wb As Workbook
Dim ws As Worksheet
Dim objName As Name
Dim sWsName As String
Dim sWbName As String
Dim sRefersTo As String
Dim sObjName As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
sWsName = ws.Name
sWbName = wb.Name
'Loop through names in worksheet.
For Each objName In ws.Names
'Check name is visible.
If objName.Visible = True Then
'Check name refers to a range on the active sheet.
If InStr(1, objName.RefersTo, sWsName, vbTextCompare) Then
sRefersTo = objName.RefersTo
sObjName = objName.Name
'Check name is scoped to the worksheet.
If objName.Parent.Name <> sWbName Then
'Delete the current name scoped to worksheet replacing with workbook scoped name.
sObjName = Mid(sObjName, InStr(1, sObjName, "!") + 1, Len(sObjName))
objName.Delete
wb.Names.Add Name:=sObjName, RefersTo:=sRefersTo
End If
End If
End If
Next objName
End Sub
Sub RescopeNamedRangesToWorksheet()
Dim wb As Workbook
Dim ws As Worksheet
Dim objName As Name
Dim sWsName As String
Dim sWbName As String
Dim sRefersTo As String
Dim sObjName As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
sWsName = ws.Name
sWbName = wb.Name
'Loop through names in worksheet.
For Each objName In wb.Names
'Check name is visble.
If objName.Visible = True Then
'Check name refers to a range on the active sheet.
If InStr(1, objName.RefersTo, sWsName, vbTextCompare) Then
sRefersTo = objName.RefersTo
sObjName = objName.Name
'Check name is scoped to the workbook.
If objName.Parent.Name = sWbName Then
'Delete the current name scoped to workbook replacing with worksheet scoped name.
objName.Delete
ws.Names.Add Name:=sObjName, RefersTo:=sRefersTo
End If
End If
End If
Next objName
End Sub
Sub Review()
Dim Review As Worksheet
If MidSub <> vbYes Then Call TurnStuffOff
On Error GoTo Create
Summarise:
Set Review = Sheets("Review")
If Review.Range("A6") <> "R&D" Then
Answer = MsgBox("The review tab currently contained within this workbook is not in the standard format." _
& vbNewLine & vbNewLine & "Would you like to recreate it?", vbExclamation + vbYesNo, "Recreate Review?")
If Answer = vbYes Then Application.DisplayAlerts = False: Review.Delete: GoTo Create
Exit Sub
End If
Set ColA = Review.Range("A:A")
Set ColB = Review.Range("B:B")
Set ColC = Review.Range("C:C")
Set ColD = Review.Range("D:D")
On Error GoTo -1
On Error Resume Next
For Each Sheet In ActiveWorkbook.Sheets
SLink = "#'" & Sheet.Name & "'!"
SHyp = "=HYPERLINK(""" & SLink & "A1"",""" & Format(Sheet.Index, "00") & ". " & Sheet.Name & """)"
'Cycle through each note in the sheet.
For Each note In Sheet.Comments
ReviewerU = 0
SHypU = ""
Noted = ""
Reviewer = Left(note.Author, 1) & Mid(note.Author, InStr(note.Author, " ") + 1, 1) & ": " & Date
cRef = Replace(note.Parent.Address, "$", "")
CLink = "#'" & Sheet.Name & "'!" & note.Parent.Address
CHyp = "=HYPERLINK(""" & CLink & """,""" & cRef & """)"
CTxt = Right(note.Text, Len(note.Text) - InStr(note.Text, ":") - 1)
'Ensure Note has not already been recorded.
Noted = ColD.Find(CTxt).Row
If Noted <> "" Then
Set a = ColD.Find(CTxt)
Set B = a
Do Until Looped = vbYes
Set B = ColD.FindNext(B)
If B.Offset(0, -1) = cRef And B.Offset(0, -2) = Sheet.Name Then GoTo NextC
If a.Address = B.Address Then Looped = vbYes
Loop
Looped = vbNo
End If
'Marks the rows in which the same "R&D" (Col A) entries have previously been made.
ReviewerU = ColA.SpecialCells(xlCellTypeConstants).Find(Reviewer).Row
If Review.Range("A7") <> Reviewer Then Review.Range("7:8").Insert: Review.Range("7:8").Font.Bold = False Else Review.Range("7:7").Insert: Review.Range("7:7").Font.Bold = False
If ReviewerU < Review.Range("C1").End(xlDown).Row Then ColA.SpecialCells(xlCellTypeConstants).Find(Reviewer).ClearContents
Review.Range("A7") = Reviewer: Review.Range("B7") = SHyp: Review.Range("C7") = CHyp: Review.Range("D7") = CTxt
NextC:
Next note
'Cycle through each comment in the sheet.
For Each CT In Sheet.CommentsThreaded
ReviewerU = 0
SHypU = ""
Noted = ""
Reviewer = Left(CT.Author.Name, 1) & Mid(CT.Author.Name, InStr(CT.Author.Name, " ") + 1, 1) & ": " & WorksheetFunction.Text(CT.Date, "DD/MM/YYYY")
cRef = Replace(CT.Parent.Address, "$", "")
CLink = "#'" & Sheet.Name & "'!" & CT.Parent.Address
CHyp = "=HYPERLINK(""" & CLink & """,""" & cRef & """)"
CTxt = CT.Text
'Ensure comment has not already been recorded.
Noted = ColD.Find(CTxt).Row
If Noted <> "" Then
Set a = ColD.Find(CTxt)
Set B = a
Do Until Looped = vbYes
Set B = ColD.FindNext(B)
If B.Offset(0, -1) = cRef And B.Offset(0, -2) = Sheet.Name Then GoTo NextCT
If a.Address = B.Address Then Looped = vbYes
Loop
Looped = vbNo
End If
'Marks the rows in which the same "R&D" (Col A) entries have previously been made.
ReviewerU = ColA.SpecialCells(xlCellTypeConstants).Find(Reviewer).Row
If Review.Range("A7") <> Reviewer Then Review.Range("7:8").Insert: Review.Range("7:8").Font.Bold = False Else Review.Range("7:7").Insert: Review.Range("7:7").Font.Bold = False
If ReviewerU < Review.Range("C1").End(xlDown).Row Then ColA.SpecialCells(xlCellTypeConstants).Find(Reviewer).ClearContents
Review.Range("A7") = Reviewer: Review.Range("B7") = SHyp: Review.Range("C7") = CHyp: Review.Range("D7") = CTxt
NextCT:
Next CT
NextSh:
Next Sheet
Review.Activate
ActiveSheet.Tab.Color = vbRed
Cells.VerticalAlignment = xlTop
Cells.Font.Name = "Calibri"
Cells.Font.Size = 8
Cells.Font.Bold = False
Range("D:D").WrapText = True
Range("A1:A3").Font.Bold = True
Range("A1:A3").Font.Size = 10
Rows(6).Font.Bold = True
Rows(6).Font.Size = 9
Rows(6).VerticalAlignment = xlBottom
Columns(1).ColumnWidth = 15
Columns(2).ColumnWidth = 15
Columns(3).ColumnWidth = 8
Columns(4).ColumnWidth = 50
Columns(5).ColumnWidth = 15
Columns(6).ColumnWidth = 50
Cells.EntireRow.AutoFit
If MidSub <> vbYes Then Call TurnStuffOn
Exit Sub
Create:
ActiveWorkbook.Worksheets.Add(Sheets(1)).Name = "Review"
Range("A1") = "=UPPER(Company)"
Range("A2") = "SUMMARISED REVIEW COMMENTS"
Range("A3") = "AS AT " & UCase(Format(Date, "DD MMMM YYYY"))
Range("A6") = "R&D"
Range("B6") = "Sheet"
Range("C6") = "Cell"
Range("D6") = "Comment"
Range("E6") = "R&D"
Range("F6") = "Response"
GoTo Summarise
End Sub
Sub Std_Lead()
If MidSub <> vbYes Then Call TurnStuffOff
Cells.Font.Name = "Calibri"
Cells.Font.Size = 8
Range("A1:A3").Select
Selection.Font.Size = 10
Selection.Font.Bold = True
If MidSub <> vbYes Then Undo = vbYes: MidSub = vbYes
Call Add_UPPER
If Undo = vbYes Then MidSub = vbNo
Range("A1").Select
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub SUMIFS_Breakdown()
'Note that this is unfortunately a draft macro at this stage and is not guaranteed to work in all scenarios.
'Note the following shorthand: f = "Function"; c = "Criteria"; l = "Loop"
If MidSub <> vbYes Then Call TurnStuffOff
Dim Cell As Range, Breakdown As New Collection
Rtn = ActiveSheet.Name
x0 = Selection.Column
y0 = Selection.Row
For Each Sheet In ActiveWorkbook.Sheets
If Sheet.Name Like "Breakdown*" Then i = i + 1
Next Sheet
y1 = 6
For Each Cell In Selection
If Cell.Value = 0 Then GoTo Next_Cell
If InStr(Cell.Formula, "SUMIF") = 0 Then GoTo Next_Cell
If InStr(Cell.Formula, "[") = 0 Then GoTo Next_Cell
cRef = "'" & Rtn & "'!" & Cell.Address(0, 0)
i = i + 1
Sheets.Add(After:=ActiveSheet).Name = "Breakdown " & i
Range("A1") = Sheets(Rtn).Range("A1").Value
Range("A2") = "=Hyperlink(""#" & cRef & """,""Breakdown of " & cRef & """)"
Range("A3") = "=UPPER(""As at ""&TEXT(CPE,""DD MMMM YYYY""))"
fStart = 1
Restart:
If InStr(fStart, Cell.Formula, "SUMIFS") <> 0 Then
'Find the SUMIFS string.
fStart = InStr(fStart, Cell.Formula, "SUMIFS") + 7
bCount = 1
For i = fStart To Len(Cell.Formula)
If Mid(Cell.Formula, i, 1) = "(" Then
bCount = bCount + 1
ElseIf Mid(Cell.Formula, i, 1) = ")" Then
bCount = bCount - 1
End If
If bCount = 0 Then
fEnd = i
Exit For
End If
Next i
fString = Mid(Cell.Formula, fStart, fEnd - fStart)
fStart = fEnd
'Define the referenced range, but only proceed with table ranges.
If InStr(fString, "[") Then fRange = Mid(fString, 1, InStr(fString, "[") - 1): Range(fRange & "[#Headers]").Copy Cells(y1, 1)
Range(fRange).AutoFilter
On Error GoTo -1: On Error GoTo Actioned
lStart = InStr(fString, ",")
i = 0
Do Until lStart > Len(fString)
Ary = vbNo
'Find filters and place these into the criteria range.
cRange = Mid(fString, InStr(lStart, fString, "[") + 1, InStr(lStart, fString, "]") - InStr(lStart, fString, "[") - 1)
x1 = Rows(6).Find(cRange, LookAt:=xlWhole).Column
lStart = lStart + Len(fRange & cRange) + 4
IsArray: If InStr(lStart, fString, ",") <> 0 Then cDetail = Mid(fString, lStart, InStr(lStart, fString, ",") - lStart) Else cDetail = Mid(fString, lStart, Len(fString) - lStart + 1)
lStart = lStart + Len(cDetail)
If InStr(cDetail, "{") Then Ary = vbYes
If InStr(cDetail, "}") Then Ary = "EndA"
If cDetail Like "*!*" Then cDetail = Range(cDetail).Value
If InStr(cDetail, "@") > 0 Then
x = Sheets(Rtn).Cells.Find(Replace(Replace(Replace(cDetail, "@", ""), "[", ""), "]", "")).Column
cDetail = Sheets(Rtn).Cells(y0, x).Value
x = ""
GoTo Plant
End If
If InStr(cDetail, """") = 0 Then cDetail = Range(Rtn & "!" & cDetail).Value
If InStr(cDetail, """&") Or InStr(cDetail, "&""") Then
x = Mid(cDetail, InStr(cDetail, "&") + 1, Len(cDetail) - InStr(cDetail, "&") + 1)
If InStr(x, "&") > 0 Then x = Left(x, InStr(x, "&"))
End If
cDetail = Replace(Replace(Replace(Replace(Replace(cDetail, "&""", ""), """&", ""), """", ""), "{", ""), "}", "")
If x <> "" Then cDetail = Replace(cDetail, x, CLng(Range(x).Value))
If InStr(cDetail, "/") Then cDetail = DateValue(cDetail)
If Ary <> vbNo And i <> 0 Then Rows(y1 + 1).FillDown
Plant: Cells(y1 + 1, x1) = cDetail
If Ary = vbYes Then i = i + 1: y1 = y1 + 1: lStart = lStart + 1: GoTo IsArray
Loop
y1 = y1 - i
Set cRg = Cells(y1, 1).CurrentRegion
y = Cells(y1, 1).CurrentRegion.Rows.Count + y1 + 1
Range(fRange & "[#All]").Copy Cells(y, 1)
On Error GoTo -1: On Error Resume Next
xLCY = Rows(6).Find("A*LCY", LookAt:=xlPart).Column
xRCY = Rows(6).Find("A*RCY", LookAt:=xlPart).Column
y2 = Range("A1").SpecialCells(xlCellTypeLastCell).Row + 2
Cells(y, 1).CurrentRegion.AdvancedFilter xlFilterInPlace, cRg, Cells(y + 1, 1)
Cells(y, 1).CurrentRegion.SpecialCells(xlCellTypeVisible).Copy Cells(y2, 1)
ActiveSheet.ShowAllData
Rows(y1 & ":" & y2 - 1).EntireRow.Delete
If Cells(y1, 1).CurrentRegion.Rows.Count <> 1 Then
Cells(y1, 1).CurrentRegion.Columns.AutoFit
y1 = y1 + 1: y2 = Cells(y1, 1).End(xlDown).Row
Cells(y2 + 1, xLCY) = "=SUBTOTAL(109," & Cells(y1, xLCY).Address(0, 0) & ":" & Cells(y2, xLCY).Address(0, 0) & ")": Cells(y2 + 1, xRCY) = "=SUBTOTAL(109," & Cells(y1, xRCY).Address(0, 0) & ":" & Cells(y2, xRCY).Address(0, 0) & ")"
Range(Cells(y1, xLCY), Cells(y2 + 1, xLCY)).NumberFormat = "_-* #,##0.00_-;_-* (#,##0.00);_-* ""-""??_-;_-@_-"
Range(Cells(y1, xRCY), Cells(y2 + 1, xRCY)).NumberFormat = "_-* #,##0.00_-;_-* (#,##0.00);_-* ""-""??_-;_-@_-"
y1 = y2 + 3
End If
GoTo Restart
ElseIf InStr(fStart, Cell.Formula, "SUMIF") <> 0 Then
'Find the SUMIF string.
fStart = InStr(fStart, Cell.Formula, "SUMIF") + 6
bCount = 1
For i = fStart To Len(Cell.Formula)
If Mid(Cell.Formula, i, 1) = "(" Then
bCount = bCount + 1
ElseIf Mid(Cell.Formula, i, 1) = ")" Then
bCount = bCount - 1
End If
If bCount = 0 Then
fEnd = i
Exit For
End If
Next i
fString = Mid(Cell.Formula, fStart, fEnd - fStart)
fStart = fEnd
'Define the referenced range, but only proceed with table ranges.
If InStr(fString, "[") Then fRange = Mid(fString, 1, InStr(fString, "[") - 1): Range(fRange & "[#Headers]").Copy Cells(y1, 1)
On Error GoTo -1: On Error GoTo Actioned
'Find filter and place these into the criteria range.
t1 = InStr(fString, ",")
t2 = InStr(t1 + 1, fString, ",")
cRange = Mid(fString, InStr(fString, "[") + 1, InStr(fString, "]") - InStr(fString, "[") - 1)
cDetail = Mid(fString, t1 + 1, t2 - t1 - 1)
If cDetail Like "*!*" Then cDetail = Range(cDetail).Value
If InStr(cDetail, """") = 0 Then cDetail = Range(Rtn & "!" & cDetail).Value
If InStr(cDetail, "&") > 0 Then
x = Mid(cDetail, InStr(cDetail, "&") + 1, Len(cDetail) - InStr(cDetail, "&") + 1)
If InStr(x, "&") > 0 Then x = Left(x, InStr(x, "&"))
End If
cDetail = Replace(Replace(Replace(cDetail, "&""", ""), """&", ""), """", "")
If x <> "" Then cDetail = Replace(cDetail, x, Range(x).Formula)
Cells(y1 + 1, Rows(6).Find(cRange, LookAt:=xlWhole).Column) = cDetail
Set cRg = Cells(y1, 1).CurrentRegion
y = Cells(y1, 1).CurrentRegion.Rows.Count + y1 + 1
Range(fRange & "[#All]").Copy Cells(y, 1)
On Error GoTo -1: On Error Resume Next
xLCY = Rows(6).Find("A*LCY", LookAt:=xlPart).Column
xRCY = Rows(6).Find("A*RCY", LookAt:=xlPart).Column
y2 = Range("A1").SpecialCells(xlCellTypeLastCell).Row + 2
Cells(y, 1).CurrentRegion.AdvancedFilter xlFilterInPlace, cRg, Cells(y + 1, 1)
Cells(y, 1).CurrentRegion.SpecialCells(xlCellTypeVisible).Copy Cells(y2, 1)
ActiveSheet.ShowAllData
Rows(y1 & ":" & y2 - 1).EntireRow.Delete
If Cells(y1, 1).CurrentRegion.Rows.Count <> 1 Then
Cells(y1, 1).CurrentRegion.Columns.AutoFit
y1 = y1 + 1: y2 = Cells(y1, 1).End(xlDown).Row
Cells(y2 + 1, xLCY) = "=SUBTOTAL(109," & Cells(y1, xLCY).Address(0, 0) & ":" & Cells(y2, xLCY).Address(0, 0) & ")": Cells(y2 + 1, xRCY) = "=SUBTOTAL(109," & Cells(y1, xRCY).Address(0, 0) & ":" & Cells(y2, xRCY).Address(0, 0) & ")"
Range(Cells(y1, xLCY), Cells(y2 + 1, xLCY)).NumberFormat = "_-* #,##0.00_-;_-* (#,##0.00);_-* ""-""??_-;_-@_-"
Range(Cells(y1, xRCY), Cells(y2 + 1, xRCY)).NumberFormat = "_-* #,##0.00_-;_-* (#,##0.00);_-* ""-""??_-;_-@_-"
y1 = y2 + 3
End If
GoTo Restart
End If
Actioned: Actioned = vbYes
Next_Cell: Next
If Actioned = vbYes Then MidSub = vbYes: Call Std_Lead: MidSub = vbNo
If Actioned <> vbYes Then MsgBox "This macro should only be run on cells containing a SUMIF(S) function that reference a tabular range. None of these cells fit this criteria.", vbInformation + vbOKOnly, "Nothing happened..."
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Un_Protect_Sheet()
'This macro protects or unprotects the active sheet as necessary.
On Error GoTo Leave
If ActiveSheet.ProtectContents Then ActiveSheet.Unprotect Password:="MgmtOnly": Exit Sub
ActiveSheet.Protect Password:="MgmtOnly", AllowFormattingRows:=True
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.EnableSelection = xlLockedCells
Exit Sub
Leave:
MsgBox "Macro didn't work as password is not standard. Try something else manually.", vbCritical, "Failure!"
End Sub
Sub UnhideAllSheets()
'This macro unhides all worksheets within a given document, which can be incredibly useful when there are many hidden sheets.
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Visible = xlSheetVisible
Next Worksheet
End Sub
Sub Unhighlight_Cells()
For Each ws In ActiveWindow.SelectedSheets
ws.Cells.Interior.ColorIndex = 0
Next ws
MsgBox "All cells within the selected sheets have been unhighlighted. Any remaining highlights are due to conditional or table formatting."
End Sub
Sub Unmerge_Redundants()
If MidSub <> vbYes Then Call TurnStuffOff
On Error Resume Next
For Each Sheet In ActiveWorkbook.Sheets
For Each Cell In Sheet.UsedRange
x = Sheet.Name
If Cell.Address = Cell.MergeArea.Address Then GoTo Next_Cell
Set MrgRng = Sheet.Range(Cell.MergeArea.Address)
UnMrg = vbYes
For Each cM In MrgRng
If cM.Value <> "" Then UnMrg = vbNo
Next cM
If UnMrg = vbYes Then Cell.UnMerge
Next_Cell:
Next Cell
Next Sheet
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Sub Zoom100()
If MidSub <> vbYes Then Call TurnStuffOff
Set ReturnTo = ActiveSheet
For Each Sheet In ActiveWorkbook.Sheets
On Error GoTo -1
On Error GoTo Skip
If Sheet.Visible = False Then Hide = vbYes: Sheet.Visible = True
Sheet.Activate
ActiveWindow.Zoom = 100
If Hide = vbYes Then Sheet.Visible = False
Skip:
Hide = vbNo
Next Sheet
ReturnTo.Activate
If MidSub <> vbYes Then Call TurnStuffOn
End Sub
Private Sub TurnStuffOff()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
End Sub
Private Sub TurnStuffOn()
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
End Sub