Beam Me Up Scotty – Excel Hyperlinks

Share

Facebook
Twitter
LinkedIn

What are Hyperlinks ?

A Hyperlink is a reference to a document, a location or an action that the reader can directly follow by selecting the link.

Hyperlinks are used extensively on the Internet and are generally Words highlighted in Underlined Blue <– Like that.

The use of Hyperlinks in Excel has been extended to a number of areas and this includes:

  • Opening Files (of any type)
  • Opening Web Pages (Internet or Intranet)
  • Jumping/Navigating to locations within an existing document
  • Creating New Documents (Excel files only)
  • Sending Emails

Microsoft has added the ability to place Hyperlinks,

  • Directly on an Excel worksheet ,
  • Connected to a number of worksheet objects, including shapes, charts and wordart
  • Included as a worksheet formulas.
  • Programmatically using VBA

These 4 methods above will be discussed here.

Inserting Hyperlinks

As described above there are 4 methods for inserting hyperlinks in an Excel Workbook.

Directly on an Excel worksheet

There are 3 ways to insert a Hyperlink directly into a cell, either:

Right click on the cell and select Hyperlink; or

Use the Insert, Hyperlinks Tab; or

Use a Keyboard Shortcut – Ctrl K

Connected to a number of worksheet objects, including shapes, charts and wordart

You can also add a Hyperlink to many objects within Excel including Pictures, Shapes, Text Boxes, Word Art and Charts.

Right clicking a lot of these objects brings up the Objects Shortcuts Menu, select Hyperlink…,

or

Select the object, Use the Insert, Hyperlinks Tab; or

Select the Object and Use the Keyboard Shortcut – Ctrl K

Hint: Right Clicking on Charts Doesn’t Show the Add Hyperlink option, so Select the Chart and Ctrl K

Adding Hyperlinks using Worksheet Formulas.

Hyperlinks can be added using worksheet formulas.

=HYPERLINK( Link Location, Name)

Link Location: This is the path and file name to the document to be opened.

The Link Location can refer to a place in a document – such as a specific cell or named range in an Excel worksheet or workbook, or to a bookmark in a Microsoft Word document. The path can be to a file that is stored on a hard disk drive. The path can also be the path on a server or a URL, HTTP or FTP and a location of an object, document, World Wide Web page, or other destination on the Internet or an intranet. The Link Location can be a text string enclosed in quotation marks or a reference to a cell that contains the link as a text string.

Name: This is the text or value that is displayed in the cell.  The Name is displayed in blue and is underlined.

Eg:

Jump to a cell on Another sheet

=HYPERLINK(Sheet3!B3,”Monthly Budget”)

The above  will add a Hyperlink, titled “Monthly Budget” and link to Sheet3!B3 of the current workbook

Jump to a Named Range on Another sheet

=HYPERLINK(Budget,”Yearly Budget”)

The above  will add a Hyperlink, titled “Yearly Budget” and link to the Named Range “Budget” of the current workbook

Open a File on a network Drive

=HYPERLINK(“//Server01\01 Administration\Administration.docx”,”Open Admin File”)

The above  will add a Hyperlink, titled “Open Admin File” and link to the file at: //Server01\01 Administration\Administration.docx

Open a File on a network Drive at a specific bookmark

=HYPERLINK(“[//Server01\01 Administration\Administration.docx]Contents”,”Open Admin File @ TOC”)

The above  will add a Hyperlink, titled “Open Admin File @ TOC” and link to the Named Section “Contents” of the file at: //Server01\01 Administration\Administration.docx

Jump to a Web Page

=HYPERLINK(“http://chandoo.org/wp/”,”Goto Chandoo.org”)

The above  will add a Hyperlink, titled “Goto Chandoo.org” and link to http://chandoo.org/wp/

Send an Email

=HYPERLINK(“mailto:chandoo.d@gmail.com”,”Email Chandoo”)

The above will add a Hyperlink, titled “Email Chandoo” and send an email to chandoo.d@gmail.com

Adding Hyperlinks Programmatically using VBA

Hyperlinks can be added to a worksheet or a worksheet object programmatically using some simple code

Sheets(SheetName).Hyperlinks.Add Anchor:=Sheets(SheetName).Range(Range), Address:=””,  SubAddress:=”Address!Range“,  TextToDisplay:=Name

Where:

SheetName: The Name of the Sheet where the Hyperlink is to go

Range:  The Range where the Hyperlink is to go

Address!Range: The address and Range linked to in the Hyperlink

Name: The Display Name of the Hyperlink

Types of Hyperlinks

There are 5 Types of Hyperlinks which Excel offers, each is described below:

  • Existing File
  • Existing Web Page
  • Place in This Document
  • Create a New Document
  • Send an Email Link

Existing File

Select the existing File or Web Page icon in the Link to: area

Navigate to the existing file using the Look in: area of the dialog

Add your Display Text in the Text to display: area

Add a ScreenTip…, a Tip which is displayed when you hover the mouse over a Hyperlink

Use the Bookmark… button to jump to predefined Named Ranges and common Cell References dialog

Existing Web Page

Select the Existing File or Web Page icon in the Link to: area

Navigate to the existing file using the Look in: area of the dialog

Add your Display Text in the Text to display: area

Add a ScreenTip…, a Tip which is displayed when you hover the mouse over a Hyperlink

Place in This Document

Select the Place in this Document icon in the Link to: area

Type in Cell Reference using the Type in Cell Reference: area of the dialog or select a Defined Names in the Defined Names area

Add your Display Text in the Text to display: area

Add a ScreenTip…, a Tip which is displayed when you hover the mouse over a Hyperlink


Create a New Document

Select the Create New Document icon in the Link to: area

Type in the Name of the New Document in the Name of the New Document: area of the dialog.

Add your Display Text in the Text to display: area

Add a ScreenTip…, a Tip which is displayed when you hover the mouse over a Hyperlink

You can choose wether to Edit the File Now or Later in the When to Edit area

Send an Email Link

Select the Email Address icon in the Link to: area

Type in the Email Address in the Email Address: area of the dialog.

Add your Display Text in the Text to display: area

Add your Email Subject in the Subject: area

Add a ScreenTip…, a Tip which is displayed when you hover the mouse over a Hyperlink.

Editing Hyperlinks

Once you have a hyperlink established you can edit the hyperlink by right click on the hyperlink and select Edit Hyperlink

The Edit Hyperlink dialog will vary depending on the type of Hyperlink as described above.

Deleting Hyperlinks

Once you have a hyperlink established you can delete the hyperlink by right click on the hyperlink and select Remove Hyperlink


Hyperlink Uses

Hyperlink can be used for a number of uses as described above.

Tables of Contents

One common use of hyperlinks is the creation of Tables of Contents.

The construction of a Table of Contents page was discussed here Table of Contents

The construction of Tables of Contents can also be automated using some simple VBA.

So instead of reinventing the wheel I will direct you to The Microsoft Office Blog where Tables of Conents were recently discussed.

Table of Contents 1 or Table of Contents 2

Dealing with Lots of Hyperlinks

The following 2 posts at http://chandoo.org/forums have solved users problems and will easily be adapted to other Hyperlink issues

Find Dead Hyperlinks

http://chandoo.org/forums/topic/check-broken-external-hyperlinks

Edit Hyperlinks

http://chandoo.org/forums/topic/marco-for-editing-link-in-workbook

How have you used Hyperlinks?

How have you used Hyperlinks?

Let us all know in the comments below:

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

20 Responses to “Simulating Dice throws – the correct way to do it in excel”

  1. alpha bravo says:

    You have an interesting point, but the bell curve theory is nonsense. Certainly it is not what you would want, even if it were true.

  2. Karl says:

    Alpha Bravo - Although not a distribution curve in the strict sense, is does reflect the actual results of throwing two physical dice.

    And reflects the following . .
    There is 1 way of throwing a total of 2
    There are 2 ways of throwing a total of 3
    There are 3 ways of throwing a total of 4
    There are 4 ways of throwing a total of 5
    There are 5 ways of throwing a total of 6
    There are 6 ways of throwing a total of 7
    There are 5 ways of throwing a total of 8
    There are 4 ways of throwing a total of 9
    There are 3 ways of throwing a total of 10
    There are 2 ways of throwing a total of 11
    There is 1 way of throwing a total of 12

  3. Chandoo says:

    @alpha bravo ... welcome... 🙂

    either your comment or your dice is loaded 😉

    I am afraid the distribution shown in the right graph is what you get when you throw a pair of dice in real world. As Karl already explained, it is not random behavior you see when you try to combine 2 random events (individual dice throws), but more of order due to how things work.

    @Karl, thanks 🙂

  4. Jon Peltier says:

    When simulating a coin toss, the ROUND function you used is appropriate. However, your die simulation formula should use INT instead of ROUND:

    =INT(RAND()*6)+1

    Otherwise, the rounding causes half of each number's predictions to be applied to the next higher number. Also, you'd get a count for 7, which isn't possible in a die.

    To illustrate, I set up 1200 trials of each formula in a worksheet and counted the results. The image here shows the table and a histogram of results:

    http://peltiertech.com/WordPress/wp-content/img200808/RandonDieTrials.png

  5. Chandoo says:

    @Jon: thanks for pointing this out. You are absolutely right. INT() is what I should I have used instead of ROUND() as it reduces the possibility of having either 1 or 6 by almost half that of having other numbers.

    this is such a good thing to learn, helps me a lot in my future simulations.

    Btw, the actual graphs I have shown were plotted based on randbetween() and not from rand()*6, so they still hold good.

    Updating the post to include your comments as it helps everyone to know this.

  6. Jon Peltier says:

    By the way, the distribution is not a Gaussian distribution, as Karl points out. However, when you add the simulations of many dice together (i.e., ten throws), the overall results will approximate a Gaussian distribution. If my feeble memory serves me, this is the Central Limit Theorem.

  7. Chandoo says:

    @Jon, that is right, you have to nearly throw infinite number of dice and add their face counts to get a perfect bell curve or Gaussian distribution, but as the central limit theorem suggests, our curve should roughly look like a bell curve... 🙂

  8. [...] posts on games & excel that you may enjoy: Simulating Dice throws in Excel Generate and Print Bingo / Housie tickets using this excel Understanding Monopoly Board [...]

  9. YourFifthGradeMathsTeacher says:

    I'm afraid to say that this is a badly stated and ambiguous post, which is likely to cause errors and misunderstanding.
    Aside from the initial use of round() instead of int(),.. (you've since corrected), you made several crucial mistakes by not accurately and unambiguously stating the details.

    Firstly, you said:
    "this little function generates a random fraction between 0 and 1"
    Correctly stated this should be:
    "this little function generates a random fraction F where 0 <= F < 1".

    Secondly, I guess because you were a little fuzzy about the exact range of values returned by rand(), you have then been just as ambiguous in stating:
    "I usually write int(rand()*12)+1 if I need a random number between 0 to 12".
    (that implies 13 integers, not 12)

    Your formula, does not return 13 integers between 0 to 12.
    It returns 12 integers between 1 and 12 (inclusive).
    -- As rand() returns a random fraction F where 0 <= F < 1, you can obviously can only get integers between 1 and 12 (inclusive) from your formula as stated above, but clearly not zero.

    If you had said either:
    "I usually write int(rand()*12) if I need a random number between 0 to 11 (inclusive)",
    or:
    "I usually write int(rand()*12)+1 if I need a random number between 1 to 12 (inclusive)"
    then you would have been correct.

    Unfortunately, you FAIL! -- repeat 5th grade please!

    Your Fifth Grade Maths Teacher

  10. Justin says:

    Idk if I'm on the right forum for this or how soon one can reply, but I'm working on a test using Excel and I have a table set up to get all my answers from BUT I need to generate 10,000 answers from this one table. Every time, I try to do this I get 10,000 duplicate answers. I know there has to be some simple command I have left out or not used at all, any help would be extremely helpful! (And I already have the dice figured out lol)

    Roll 4Dice with 20Sides (4D20) if the total < 20 add the sum of a rerolled 2D20. What is the average total over 10,000 turns? (Short and sweet)

    Like I said when I try to simulate 10,000turns I just get "67" 10,000times -_- help please! 😀

  11. Hui... says:

    @Justin

    This is a good example to use for basic simulation

    have a look at the file I have posted at:
    https://rapidshare.com/files/1257689536/4_Dice.xlsx

    It uses a variable size dice which you set
    Has 4 Dice
    Throws them 10,000 times
    If Total per roll < 20 uses the sum of 2 extra dice Adds up the scores Averages the results You can read more about how it was constructed by reading this post: http://chandoo.org/wp/2010/05/06/data-tables-monte-carlo-simulations-in-excel-a-comprehensive-guide/

  12. SpreadSheetNinja says:

    Oh derp, i fell for this trap too, thinking i was makeing a good dice roll simulation.. instead of just got an average of everything 😛

    Noteably This dice trow simulate page is kinda important, as most roleplay dice games were hard.. i mean, a crit failure or crit hit (rolling double 1's or double 6's) in a a game for example dungeons and dragons, if you dont do the roll each induvidual dice, then theres a higher chance of scoreing a crit hit or a crit failure on attacking..

  13. Freswinn says:

    I've been working on this for awhile. So here's a few issues I've come across and solved.

    #1. round() does work, but you add 0.5 as the constant, not 1.

    trunc() and int() give you the same distributions as round() when you use the constant 1, so among the three functions they are all equally fair as long as you remember what you're doing when you use one rather than the other. I've proven it with a rough mathematical proof -- I say rough only because I'm not a proper mathematician.

    In short, depending on the function (s is the number of sides, and R stands in for RAND() ):

    round(f), where f = sR + 0.5
    trunc(f), where f = sR + 1
    int(f), where f = sR + 1

    will all give you the same distribution, meaning that between the three functions they are fair and none favors something more than the others. However...

    #2. None of the above gets you around the uneven distribution of possible outcomes of primes not found in the factorization of the base being used (base-10, since we're using decimal; and the prime factorization of 10 is 2 and 5).

    With a 10-sided die, where your equation would be
    =ROUND(6*RAND()+0.5)
    Your distribution of possible values is even across all ten possibilities.
    However, if you use the most basic die, a 6-sided die, the distributions favor some rolls over others. Let's assume your random number can only generate down to the thousandths (0.000 ? R ? 0.999). The distribution of possible outcomes of your function are:
    1: 167
    2: 167
    3: 166
    4: 167
    5: 167
    6: 166

    So 4 and 6 are always under-represented in the distribution by 1 less than their compatriots. This is true no matter how many decimals you allow, though the distribution gets closer and closer to equal the further towards infinite decimal places you go.
    This carries over to all die whose numbers of sides do not factor down to a prime factorization of some exponential values of 2 and 5.

    So, then, how can we fix this one, tiny issue in a practical manner that doesn't make our heads hurt or put unnecessary strain on the computer?

  14. Freswinn says:

    Real quick addendum to the above:
    Obviously when I put the equation after the example of the 10-sided die, I meant to put a 10*RAND() instead of a 6*RAND(). Oops!

    Also, where I have 0.000 ? R ? 0.999, the ?'s are supposed to be less-than-or-equal-to signs but the comments didn't like that. Oh well.

  15. Andrew says:

    How do you keep adding up the total? I would like to have a cell which keeps adding up the total sum of the two dices, even after a new number is generated in the cells when you refresh or generate new numbers.

  16. kk says:

    So, how do you simulate rolling 12 dice? Do you write int(rand()*6) 12 times?

    Is there a simpler way of simulating n dice in Excel?

  17. Mohammed Ali says:

    I've run this code in VBA

    Sub generate()
    Application.ScreenUpdating = False
    Application.Calculation = False
    Dim app, i As Long
    Set app = Application.WorksheetFunction

    For i = 3 To 10002
    Cells(i, 3).Value = i - 2
    Cells(i, 4).Value = app.RandBetween(2, 12)
    Cells(i, 5).Value = app.RandBetween(1, 6) + app.RandBetween(1, 6)
    Next
    Application.ScreenUpdating = True
    Application.Calculation = True
    End Sub

    But I get the same distribution for both columns 4 and 5
    Why ?

Leave a Reply