top of page

Updated: Jan 17

The Tip of the Night for May 8, 2015 concerned a macro that will check to see if links on an Excel spreadsheet are active.


The vba code below is an improvement. The code I posted about back in 2015 will generate a new worksheet in your spreadsheet with a list of the filepaths that don't work:


This vba code, posted here by Eawyne, creates a new spreadsheet which lists all of the links, and also indicates which cells the links appear in. [Be sure to use the version posted by Eawyne on 11/18/21 - not the one below it - it will give you incorrect results.]


Refer to column C to see which links do and do not exist. The linked to text appears in column H, and the cell of the original link is indicated in column B.



The code as written by Eawyne will stop after checking 1000 links. It can easily be modified by changing this line:

ReDim arr(1 To 1000, 1 To 9)

Increase the '1000' on this line of code to 9999, or whatever value you need.


It is also set to review links on multiple worksheets - something the older vba code did not do.




Public Sub CollectHyperlinks()


Dim Sht As Worksheet, Hl As Hyperlink, FSO As Object

Dim arr() As Variant, i As Long, Anchor As Object

Dim FileMsg As String, AnchorMsg As String

ReDim arr(1 To 1000, 1 To 9)

Set FSO = CreateObject("Scripting.FileSystemObject")

i = 1

arr(i, 1) = "Worksheet"

arr(i, 2) = "Hyperlink Anchor"

arr(i, 3) = "File"

arr(i, 4) = "Hyperlink Name"

arr(i, 5) = "Hyperlink Address"

arr(i, 6) = "SubAddress"

arr(i, 7) = "ScreenTip"

arr(i, 8) = "TextToDisplay"

arr(i, 9) = "EmailSubject"

For Each Sht In ThisWorkbook.Worksheets

For Each Hl In Sht.Hyperlinks

Set Anchor = Nothing

AnchorMsg = ""

FileMsg = ""

With Hl

If FSO.FileExists(.Address) Then FileMsg = "Exists"

On Error Resume Next

Set Anchor = .Range

If Not Anchor Is Nothing Then

AnchorMsg = Anchor.Address

Else

Set Anchor = .Shape

If Not Anchor Is Nothing Then

AnchorMsg = Anchor.Name

End If

End If

i = i + 1

arr(i, 1) = Sht.Name

arr(i, 2) = AnchorMsg

arr(i, 3) = FileMsg

arr(i, 4) = .Name

arr(i, 5) = .Address

arr(i, 6) = .SubAddress

arr(i, 7) = .ScreenTip

arr(i, 8) = .TextToDisplay

arr(i, 9) = .EmailSubject

On Error GoTo 0

End With

Next Hl

Next Sht

Application.ScreenUpdating = False

With Application.Workbooks.Add.Sheets(1)

.Range("A2").Select

ActiveWindow.FreezePanes = True

With .Rows("1:1")

.Interior.Color = 10837023

.Font.Color = RGB(255, 255, 255)

.Font.Bold = True

End With

.Range("A1").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr

.Columns("A:I").Columns.AutoFit

End With

Application.ScreenUpdating = True

End Sub

If you need to extract text from an Excel cell which is X number of characters before and Y number of characters after a given search term, you can use the MID and MAX formulas with a nested SEARCH formula.


A formula in this format:


=MID(A2,MAX(SEARCH("stole a",A2)-35,1),70)


. . . can be set to return the number of characters before the search string equal to the value given in the MAX formula (in this example 35) and the number of characters from the start of the search string moving to the right equal to roughly half the value given for the MID formula (in this example 70).



. . . the SEARCH formula finds the position in the cell containing text where the first character of the search term appears.



The MAX formula then gets the value of the SEARCH result minus the number entered in the complete formula. In this it is case 35.



When the result from the MAX formula is fed into the MID formula, it is used to determine the position where the extraction should begin, and how many characters after that point it should include.



When calculating data in an Excel pivot table, you're not limited to the listed options in the value field settings under the summarize value field by selection. There are lists of calculations including the sum, average, max, and minimum values for data in the pivot table. You can also input DAX, or Digital Analysis Expression, formulas in the table, which will return a table as a result. A pivot table doesn't include median values in the list of preset values, but you can enter a DAX formula which will add it to the table.




Follow these steps explained by Bill Jelen here.


  1. When selecting the data range for the pivot table select the option to add the data to the Data Model.




  1. With the data set up this way, you'll see that in the PivotTable Fields box, you have the option to 'Add Measure' when you right click on the Range.



  1. Give the new measure a name, and then enter MEDIAN as the formula selecting the field you want to analyze.


  1. Set the appropriate number format, and use the Check DAX Formula tool to confirm that the formula will function.


  1. The MEDIAN DAX formula is now listed as a new field for the Pivot table can be added to the displayed values.


Note that in this data set, the zero values are not an error. This is just showing that in each of the selected years most players had no stolen bases - except for 1908, when a majority of players had at least one stolen base.

Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page