Create a hyperlink that is dynamic - excel

In Excel 2010
On the same worksheet
I want to be able to click on Cell # A3
that click has it jump to # A8 (in the same worksheet).
and then be able to insert a row at # A6,
and still have A3 automatically jump linked to #A8
My apologies, my searches do not seem to point me to a solution. If it is there just point me there and I will see what my limited Excel skills will allow me to learn. The hardest part is learning the terminology to discover what my solution will be. FYI - I have never done a "VBA' solution in my past so that part will be a little difficult for me to understand, but I can try.
I was hoping the 'Edit Hyperlink' window's 'Type the cell reference' field would have allowed for $ character to keep the 'mapped' cell as dynamic.

You can use 'DEFINED NAME' in hyperlink. Use name box to create the defined name for your 'to be' hyperlinked cell and use that defined name to link. More step by step details is available here

In cell A3 enter the formula:
=HYPERLINK("#A8","A8")
and as Tim Williams points out, that is where it will always go.
If, however, you wanted the destination to "move" as A8 moves, you would assign a Name to the destination

Well I have a friend that found my answer that worked
One liner:
The technique is 'define the name' for the cell to be linked and use that 'defined name' in hyper link.
Ref:
http://sivajankan.blogspot.com/2015/04/excel-hyperlink-tying-to-cell.html
Before going on step by step, please find what is 'Name Box'.
Name box:
The left most cell in 'Formula bar' is the Name Box. When you hover the Name Box cell, it shows 'Enter a name for a cell range, or select a named range from the list' [in MSOffice 2013]
Step by Step:
Create the Defined Name:
Select the cell you want to be hyperlinked (to be jumped to). In the 'Name Box' [check the image above], enter a 'reference' name and press return key. [Assumed 'Reference1' for our example case]
Use the Defined Name in Hyperlink
Go to the cell where you want to place the hyperlink (to be jumped from), right click and click on 'Hyperlink' from the menu
In the 'Insert Hyperlink' popup window, in 'Anchor' ['Link to' for older version] section, click on 'locate'; which opens another popup window
In the 'Select Place in Document' popup, expand the 'Defined Names' by clicking the small triangle [or + icon] next to it [make the triangle point down, or change + to -, by clicking], and select the reference you made in step 2. [Our example 'Reference1']
Now your hyperlink pointed to the reference; so inserting or deleting any rows or columns won't affect your hyperlink pointing cell location.

Related

Running a web query with parameter from a cell within Excel

I am trying to do a GET request when I change a value in a cell.
The link here:
https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=(PARAMETER SHOULD BE HERE)&hoursBeforeNow=1
So what's in this cell, should change this query.
Is this possible, and if so, does anyone have a good solution for this?
Been trying to google all night but can't seem to find anyone that has done the same thing.
Adapting from this answer, this is a two-step process.
Firstly, create a named range for the cell that stores the value you will pass to the query. Details on how to do so are here. I used "StationName" as the name of the range but you can use any name you like.
Secondly, we need to incorporate the named range into the source for the query. To do so:
select any cell in the data table from the current query
click on the Query tab in the ribbon
click on Edit
look for the Query Settings panel at the right of the screen - if it's not there, go to View then click on Query Settings
the first entry in the Query Settings panel should be Source - click on that entry to select it
make sure that the formula bar is displayed by going to View then checking Formula Bar
the entry in the formula bar is too long to display so click on the V symbol at the end of the formula bar to expand it
edit the formula bar text to the text shown below - make sure to change the name of the Excel range shown at Name="StationName" to whichever name you have used
= Xml.Tables(Web.Contents("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=" & Excel.CurrentWorkbook(){[Name="StationName"]}[Content]{0}[Column1] & "&hoursBeforeNow=1"))
This picture shows how things should now look:
Now go to Home and click on Close & Load.
You may get a warning about privacy settings - to fix this, I chose to give both the Excel file and the aviationweather.gov site the "public" level of privacy.
You can access the privacy settings by selecting a cell in the data table, going to Query and choosing Edit, going to Home and choosing Data Source Settings, selecting Global Permissions and then using Edit Permissions on the relevant entries.
To make the query automatically refresh when the cell value changes, we need to use some VBA. We will need to know which sheet the cell is on, the name of the named range which refers to that cell and the name of the query we want to refresh. The first two should be straightforward and the name of the query is just "Query - " followed by the name shown in the Queries & Connections panel.
Open up the VBA Editor with ALT-F11, double-click on the relevant sheet object in the Project Explorer to open up the related code module and paste in the following code (but change the name of the named range and the name of the query to match your names):
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, ThisWorkbook.Names("StationName").RefersToRange) _
Is Nothing And Target.Cells.Count = 1 Then
Application.EnableEvents = False
ThisWorkbook.Connections("Query - Get station from aviationweather dot gov").Refresh
Application.EnableEvents = True
End If
End Sub
Now changing the cell value should cause the query to refresh automatically
Here's some simple code to list the name of every connection in the workbook. In the VBA editor, use Insert > Module to create a new module and then paste in the following code:
Option Explicit
Sub listConnections()
Dim c As WorkbookConnection
For Each c In ThisWorkbook.Connections
MsgBox c.Name
Next c
End Sub
Each connection name will pop up in a message box like this:
and you can just copy the name you need when it pops up. You can copy the message box contents just by hitting CTRL-C but you'll need to edit out some extra stuff when you paste. Copying the message box shown above results in the following text being placed on the clipboard:
---------------------------
Microsoft Excel
---------------------------
Query - Get station from aviationweather dot gov
---------------------------
OK
---------------------------
I get daily Exchange Rate data from cbr.ru in this fashion.
screenshot of the Connection
http://www.cbr.ru/eng/currency_base/daily/?UniDbQuery.Posted=True&UniDbQuery.To=["Ticker"]
Where i use the date as a variable from an excel cell, in such a way that it refreshes automatically once the cell value changes.
(named the parameter as Ticker)
screenshot of the Parameters
Hope this uber simple method helps.

Can't use more than one combo box on excel

I have made two active X combo boxes for a list of 220 sites. Before making the active x combo box i have made a sheet that searches through my data and finds the sites that match with what i am typing as i go.
I then used the name manage, refering to the formula in the first cell of the list
=Sheet1!$G$2:INDEX(Sheet1!$G$2:$G$220,COUNTIF(Sheet1!$G$2:$G$220,"?*"))
I have then writen this in the ListFillRange in the properties of my combo box.
It works fine for one, but once i had made the second one and selected the site the first one will no longer let me search through.
I have used the same formulas on both but they originate from different sheets to see if this fixed the problem however that was unsuccessful. (the boxes are on different sheets) When i click on the next sheet after using the box on the first sheet, it still shows part of it as if it is crashing.
The boxes are independent so I'm not sure what to do next as i need to add another 3 on separate sheets.
I am also using this code for each box
Private Sub ComboBox1_Change()
ComboBox1.ListFillRange = "MList"
Me.ComboBox1.DropDown
End Sub
and similar for the other button but with a different range.
There is no need to use VBA for this, the Change Events specifically, if you just want to use and fill the combo boxes with Named Ranges.
The scenario I think you try to do is:
Create Named Ranges that will be the source of your combobox:
Fill the range with your data, select the range, Right Click, Select Define Name and give the range a name. MList in your case I believe.
Create Combobox:
Goto Developer Tab, Insert in your case ActiveX ComboBox, Draw it on your sheet, right click the ComboBox, select properties, find ListFillRange in properties and enter the name of the Named Range you created in step one
Repeat for Combobox 2, with the same or a different Named Range depending on what you try to do
Leave Design Mode
Boths Comboboxes can now be used to type in what you are looking for.
If this is not what you tried to do, please try edit your question and in detail try to explain what you try to do and what you like to accomplish by doing so.

How to keep Worksheet hyperlink to CellA1 in each worksheet when the worksheet name is changed

I am using excel 2010 - I have 11 worksheets in a Testing plan template. The 1st Worksheet is an Overview with an Index that has Hyperlinks to the Cell A1 in each worksheet.
In each of the Worksheets in cell A1 is the formula "=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)& " Test Plan" this will update anytime the Test Plan worksheet name changes and will also add the text of " Test Plan".
On the Overview worksheet in the Index section captures whatever is in that worksheet's cell A1 - When click the Index hyperlink it'll open to that Test Plan's worksheet.
However, when the Test Plan's worksheet name changes, of course the hyperlink is no longer functional and error is displayed.
What is the best way to retain the Index Hyperlink to a Test Plan worksheet's cell 1A no matter what the worksheet name is changed to and/or how often it's changed?
Note: Each default worksheet name is Module plus the worksheet# i.e.: Module (1), Module (2), Module (3) etc...
You can use the HYPERLINK function along with a reference to a cell on the relevant worksheet. The reference will track the correct spot regardless of the sheet name. From there, you use CELL to get the address of that cell and feed it to HYPERLINK.
Formula in cell A1 on sheet Index. If you want better looking text for the cell, you can add a second parameter: =HYPERLINK(..., "prettier text to display")
=HYPERLINK(CELL("address",Data2!A1))
Picture of sheet names and result
To do this multiple times, you just need to copy the formula and change the cell reference to the next sheet. For 11 of these, that's not too bad. If you had more, you could automate the formula creation with VBA.
I have found a resolution - I was able to assign a "Defined Name" to the cell A1 for each worksheet and hyperlink from the index section on the Overview sheet to the cell A1 - and now whenever the Sheet name is changed, the hyperlink is still functional...So far that seems to be working, I have changed several of the worksheet names, and the hyperlink hasn't broken...

Excel: adding hyperlink in a cell with existing text [duplicate]

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?
a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg
I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.
By hyperlink I also refer to either
(a)another cell or,
(b)a web URL.
Thanks
After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.
For example:
Sub Tester()
Dim rng As Range
Set rng = ActiveSheet.Range("A1")
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
"Sheet1!A10", TextToDisplay:="this is long text"
With rng.Font
.ColorIndex = xlAutomatic
.Underline = xlUnderlineStyleNone
End With
With rng.Characters(Start:=9, Length:=4).Font
.Underline = xlUnderlineStyleSingle
.Color = -4165632
End With
End Sub
I needed to link to a filename displayed in a cell, so here is what worked for me:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path
This isn't possible in Excel. Hyperlinks are associated with entire cells.
If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.
The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.
CHGRow = 3
Worksheets("Page 1").Select
Cells(CHGRow, 1).Select
Do Until Application.CountA(ActiveCell.EntireRow) = 0
URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
URLText = Cells(CHGRow, cNumber)
ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText
CHGRow = CHGRow + 1
Cells(CHGRow, 1).Select
Loop
I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.
Here's a great smoke-and-mirrors solution I've used for creating hyperlinked strings within a larger block of text in an Excel spreadsheet cell. CAUTION -- if there are multiple editors for your worksheet, this is not advisable as hyperlinks can get misaligned with the text in their cells unless you can provide sufficient protection. A means of doing that is described in this procedure though may limit what contributors can do:
In your Excel spreadsheet, assuming you are not trying to protect ALL cells from editing, select all cells in the worksheet, then select Format Cells from the Home ribbon or the right-click popup menu. On the Protection tab, check then uncheck the "Locked" checkbox to ensure all cells are unlocked.
Now select the (first) cell that will contain the link.
Copy (don't cut) the text that you want to appear as a link to the clipboard.
Click anywhere in your spreadsheet (an unused area is best) and insert a text box from the Insert ribbon using either the Shape icon dropdown or the Text icon. Size and shape aren't important yet, just approximate the size of the link text.
Paste the clipboard contents into the text box.
Right click the text box and select Link to add a hyperlink to it, and specify the link target, whether a location in the current document or a URL.
Select the link text and format it how you want your links to appear, e.g. blue, underlined, etc., since inside a text box this apparently does not occur automatically as in a cell.
Right click the text box again and select Format Shape. From the Format Shape panel, perform the following in order to properly fit the shape around the text and eliminate white space and border:
(a) On the Fill & Line panel (1st icon), select the No Line option.
(b) On the Size & Properties panel (3rd icon), set all 4 margins to zero (0.00"), uncheck the "Wrap text in shape" checkbox, and check the "Resize shape to fit text" textbox."
(c) Under Properties, ensure the following are selected:
* Move but don't size with cells
* Locked
* Lock text
If you need the same hyperlink to occur in multiple cells or locations within the same cell (even if targets differ), clone the text box you did all this work on by selecting its (now invisible) border with a right click (warning - a left click will now take you to the link target instead!), copying it to the clipboard, and press Ctrl+V as many times as you need copies.
Right click on the text box (or one of them if you cloned it) and drag it to the cell where you want the link to appear, positioning it directly over the original text that matches your hyperlink, so as to visually cover it up and replace it (the original text serving as a spacer to make room for it). The steps taken in item 8 above should prevent it from covering up or clipping any text or punctuation surrounding the original text.
Select that cell, then from the Format menu on the Home ribbon, select "Lock Cell" to protect its contents from inadvertently changing and misaligning the text box with the corresponding text that its hiding.
Repeat steps 10 & 11 for each additional copy of the linked text box you created. If any of them requires a different link target, simply right click that copy of the text box, select "Edit Link", and update the target.
From the Format menu on the Home ribbon, select "Protect Sheet". Check the box labelled "Protect worksheet and contents of locked cells".
Check all the other boxes in that dialog also (assuming you are not trying to restrict users in any of those ways) except for the following:
* Format cells
* Format columns
* Format rows
* Edit objects
Leave these four checkboxes unchecked so as to protect your linked text boxes from being selected, deleted, moved, or misaligned with their underlying text. (Note: They should already move with their underlying cells if rows or columns are added, removed or resized, but without this protection they can still be impacted if their own row or column is resized.)
If you want to add a password, do so now. When finished, click OK to apply protection. You can selected "Unprotect Sheet" from the Format menu later to perform any necessary editing, but if the link cell(s), column(s) or row(s) are edited or resized, you may need to reposition the link text box(es) over the underlying text if it moved.
Test your hyperlink(s) and also what happens if you try editing the containing cell(s) or resizing the containing column(s) or row(s) to be sure the worksheet is ready for sharing!

Create a hyperlink within an Excel cell?

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?
a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg
I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.
By hyperlink I also refer to either
(a)another cell or,
(b)a web URL.
Thanks
After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.
For example:
Sub Tester()
Dim rng As Range
Set rng = ActiveSheet.Range("A1")
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
"Sheet1!A10", TextToDisplay:="this is long text"
With rng.Font
.ColorIndex = xlAutomatic
.Underline = xlUnderlineStyleNone
End With
With rng.Characters(Start:=9, Length:=4).Font
.Underline = xlUnderlineStyleSingle
.Color = -4165632
End With
End Sub
I needed to link to a filename displayed in a cell, so here is what worked for me:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path
This isn't possible in Excel. Hyperlinks are associated with entire cells.
If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.
The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.
CHGRow = 3
Worksheets("Page 1").Select
Cells(CHGRow, 1).Select
Do Until Application.CountA(ActiveCell.EntireRow) = 0
URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
URLText = Cells(CHGRow, cNumber)
ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText
CHGRow = CHGRow + 1
Cells(CHGRow, 1).Select
Loop
I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.
Here's a great smoke-and-mirrors solution I've used for creating hyperlinked strings within a larger block of text in an Excel spreadsheet cell. CAUTION -- if there are multiple editors for your worksheet, this is not advisable as hyperlinks can get misaligned with the text in their cells unless you can provide sufficient protection. A means of doing that is described in this procedure though may limit what contributors can do:
In your Excel spreadsheet, assuming you are not trying to protect ALL cells from editing, select all cells in the worksheet, then select Format Cells from the Home ribbon or the right-click popup menu. On the Protection tab, check then uncheck the "Locked" checkbox to ensure all cells are unlocked.
Now select the (first) cell that will contain the link.
Copy (don't cut) the text that you want to appear as a link to the clipboard.
Click anywhere in your spreadsheet (an unused area is best) and insert a text box from the Insert ribbon using either the Shape icon dropdown or the Text icon. Size and shape aren't important yet, just approximate the size of the link text.
Paste the clipboard contents into the text box.
Right click the text box and select Link to add a hyperlink to it, and specify the link target, whether a location in the current document or a URL.
Select the link text and format it how you want your links to appear, e.g. blue, underlined, etc., since inside a text box this apparently does not occur automatically as in a cell.
Right click the text box again and select Format Shape. From the Format Shape panel, perform the following in order to properly fit the shape around the text and eliminate white space and border:
(a) On the Fill & Line panel (1st icon), select the No Line option.
(b) On the Size & Properties panel (3rd icon), set all 4 margins to zero (0.00"), uncheck the "Wrap text in shape" checkbox, and check the "Resize shape to fit text" textbox."
(c) Under Properties, ensure the following are selected:
* Move but don't size with cells
* Locked
* Lock text
If you need the same hyperlink to occur in multiple cells or locations within the same cell (even if targets differ), clone the text box you did all this work on by selecting its (now invisible) border with a right click (warning - a left click will now take you to the link target instead!), copying it to the clipboard, and press Ctrl+V as many times as you need copies.
Right click on the text box (or one of them if you cloned it) and drag it to the cell where you want the link to appear, positioning it directly over the original text that matches your hyperlink, so as to visually cover it up and replace it (the original text serving as a spacer to make room for it). The steps taken in item 8 above should prevent it from covering up or clipping any text or punctuation surrounding the original text.
Select that cell, then from the Format menu on the Home ribbon, select "Lock Cell" to protect its contents from inadvertently changing and misaligning the text box with the corresponding text that its hiding.
Repeat steps 10 & 11 for each additional copy of the linked text box you created. If any of them requires a different link target, simply right click that copy of the text box, select "Edit Link", and update the target.
From the Format menu on the Home ribbon, select "Protect Sheet". Check the box labelled "Protect worksheet and contents of locked cells".
Check all the other boxes in that dialog also (assuming you are not trying to restrict users in any of those ways) except for the following:
* Format cells
* Format columns
* Format rows
* Edit objects
Leave these four checkboxes unchecked so as to protect your linked text boxes from being selected, deleted, moved, or misaligned with their underlying text. (Note: They should already move with their underlying cells if rows or columns are added, removed or resized, but without this protection they can still be impacted if their own row or column is resized.)
If you want to add a password, do so now. When finished, click OK to apply protection. You can selected "Unprotect Sheet" from the Format menu later to perform any necessary editing, but if the link cell(s), column(s) or row(s) are edited or resized, you may need to reposition the link text box(es) over the underlying text if it moved.
Test your hyperlink(s) and also what happens if you try editing the containing cell(s) or resizing the containing column(s) or row(s) to be sure the worksheet is ready for sharing!

Resources