In an Excel sheet (created by importing external data and images) are several cells that each contain different image and that image has a hyperlink. These cells containing images are all in one column.
How can I retrieve that hyperlink from each image?
The hyperlink is NOT retrievable from that cell.
I've got a user-defined function that easily retrieves hyperlinks from any cell (if there is a hyperlink).
Function GetURL(rng As Range) As String
On Error Resume Next
GetURL = rng.Hyperlinks(1).Address
End Function
This function can be placed anywhere.
For example: In cell c25 the URL from a hyperlink in cell A1 must be listed.
For that simply enter the following formula in cell c25.
=GetURL(A1)
That works just fine.
However, if that cell A1 contains an image with a hyperlink, then the result is nil (or nothing). Even though the hyperlink is there as part of that image.
Apparently the image is an object that needs to be addressed.
How can this be done?
Just found a possible duplicate. Unfortunately the answer didn't get me any further.
Please add sample code.
Thanks.
A shape also has a Hyperlink.Address
A shape is defined on a sheet, and also has a name.
Putting these together, I came up with the following function:
Function PicURL(Pic As String, Optional SheetName As String) As String
If SheetName = "" Then SheetName = Application.Caller.Worksheet.Name
On Error Resume Next
PicURL = Sheets(SheetName).Shapes(Pic).Hyperlink.Address
End Function
Use:
If picture is on the same sheet, then =PicURL("Picture 1") will return the target address.
If the picture is on another sheet, then =PicURL("Picture 1","Sheet1") would be needed.
If the picture is in a different worksheet, then that's a whole different ballgame, and I leave that as an exercise for the reader.
Related
I found the below link on how to copy a color based on a cell in the same sheet, however my issue is that the cells which colors have to be matched will be on cells spread out through the workbook.
Link: How to set cell color based on another cell color
My home page (1st sheet) contains a summary of information provided in the following sheets. All the relevant cells have been formatted to reflect the value of their corresponding cells in the other sheets.
So for example, My homepage cell F7 is already formatted so that it copies the value of the corresponding cell in the source sheet "Quarter 1":
=quarter1!B15
Now, what I really want is for the reproduced summary cells on my home page to also match the colors I manually select for their corresponding (source) cell the other sheets. Is this possible using VBA coding?
The source cells in question will contain dates which will be manually set - not automatically s based on value, in 3 different colors (red = uncertain; yellow = tentative; green = ok)
I got the below code from another site but it only works if the cells are on the same sheet:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("C1").Interior.Color = Me.Range("A1").Interior.Color
End Sub
Is there a way I can tweak this code to refer to a cell color (that is manually selected and not dependent on value) on another sheet in the same workbook?
Thank you so much for your help!
You just need to put the code in "Thisworkbook' with below code and need to change sheet reference instead of me. When you will change the sheet then changes will reflect in other sheet.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Sheet2.Range("C1").Interior.Color = Sheet1.Range("A1").Interior.Color
End Sub
I am wondering if there is a solution to load a picture using formula (not VBA) from a list of pictures in Excel
For example,
=IF(TODAY()-B9<8,G6,"puste")
Let's say I have a picture in cell G6, that I want the formula to return if the condition is true.
In brief, the solution can be summarized in 2 steps:
Create a linked picture cell using PasteSpecial method of Excel.
Modify the formula of linked cell to "Named Range" formula for making it dynamic.
(Optional) - If there are many cells, and one find it tiresome to manually change the address of each linked image then use the below VBA macro to assign Named Range formula to all cells.
Sub Set_Formula_Linked_Cell()
Dim rngDest As Range
Dim objPic As Object
For Each rngDest In Range("F5:O18").Cells
rngDest.Select
Set objPic = ActiveSheet.Pictures.Paste(Link:=True)
objPic.Formula = "=Country_Flag"
Set objPic = Nothing
Next
End Sub
In Detail, let's follow through a similar situation:
Let's assume we have a list of Country and their adjacent flags.
Next step is to copy the Cell (any cell which contain the flag, do not copy picture but the Cell/Range) and paste as Linked Picture in the destination cell.
Now, a careful observation in the address bar reveals that current cell which displays a flag is linked to another cell. We need to change this formula. Unfortunately, we cannot change the formula here. Either it could be a direct reference or a named range but not a formula.
We will create a "Named Range" with the name "Country_Flag" and Formula as:
=INDEX(Sheet1!$B$2:$B$6,MATCH(Sheet1!$F$3,Sheet1!$A$2:$A$6,0))
In the last Step, we will assign this named range to the linked cell.
I have a document that needs to generate a hyperlink to a cell in the same workbook by getting the address from another cell. Here's what I have right now:
=hyperlink(CELL("address",INDEX('Budget Record'!C3:C105,MATCH(Y73,'Budget Record'!C3:C105,0),1)))
This displays the appropriate location:
'[Calendar Budget.xlsx]Budget Record'!$C$3
However, when clicked, it says that Excel cannot open the specified file.
I have tried manually creating a hyperlink to that value, and it still doesn't appear to work:
=hyperlink('[Calendar Budget.xlsx]Budget Record'!$C$3)
However, if I plug that into the goto dialogue box, it has no problems with it.
Am I missing an extra step?
After looking into all of the built-in hyperlink options that Excel offers, I could not find a way to have Excel link you to a dynamic/ changing cell reference. Naturally, I turned to VBA :)... this is a very simple macro with only a few lines of code. Give it try:
Press Alt + 11 to open the Visual Basic Editor (VBE)
If your project explorer is not already open, click this icon:
Double click the worksheet tab that you want the hyperlink to work on:
Paste the following code into the white space:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'check if user is selecting the 'hyperlink' cell
If Target.Address = "$A$1" Then
'run the 'selectCell()' subroutine
Call selectCell
End If
End Sub
Sub selectCell()
Dim goToAddress As String
'get cell address
goToAddress = Range("A2").Value
'send user to this cell
Range(goToAddress).Select
End Sub
Go to your worksheet and test the script by typing G3 in cell B1.
Select cell A1. The macro should have automatically selected cell G3.
Hope this helps!
(Posted on behalf of the OP).
I have identified a solution. Basically it looks like the problem was in the formatting.
Basically I needed three steps. The first one is getting the location of the cell returned as a full address (including the file, sheet, and Cell). I do that with this:
=CELL("address",INDEX('Budget Record'!C3:C105,MATCH(Y73,'Budget Record'!C3:C105,0),1))
Here's a sample of what that results in:
'[Calendar Budget.xlsx]Budget Record'!$C$3
The problem with this is that the apostrophe at the beginning is in the wrong spot. To work as a hyperlink, the string should be this:
[Calendar Budget.xlsx]'Budget Record'!$C$3
So, I have a step where I remove the first 22 characters of the starting string:
=RIGHT(Z73,LEN(Z73)-23)
This results in the following:
Budget Record'!$C$3
Next, I need to add on this to the start of the string:
[Calendar Budget.xlsx]'
I do that with the following:
=HYPERLINK("[Calendar Budget.xlsx]'"&AA73)
The resulting output looks like this:
[Calendar Budget.xlsx]'Budget Record'!$C$3
So, we have a hyperlink to a cell in another sheet that dynamically changes depending on the initial referenced cell.
When a specific cell is clicked, I need to run a function. The function is:
HighlightOnWebsite(url As String, phrase As String)
Basically, this function loads a Web Browser Control, brings up the requested page, and highlights the required phrases. The function works more ore less fine.
What I can't figure out is how to get certain cells to call this function.
Lets say each row has 3 cells which contain the following information:
url of some document | some important phrase | will contain call to function
Now, I need to scan the spreadsheet and in the third column of each row, make a clickable cell which calls a function like HighlightOnWebsite(A1,A2).
Would something like this be possible?
You don't have to scan the worksheet.
Create, in each cell of the third column, a static hyperlink that links to that same cell.
Then have a handler in the worksheet:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Column = 3 Then
HighlightOnWebsite Target.Range.Offset(0, -2).Value, Target.Range.Offset(0, -1).Value
End If
End Sub
I need to copy a column that has linked text and paste a column that shows all the URL’s for the linked text
Function GetURL(rng As Range) As String
On Error Resume Next
GetURL = rng.Hyperlinks(1).Address
End Function
In this case you can place it where you want. If you want, for example, the URL from a hyperlink in A1 to be listed in cell C25, then in cell C25 you would enter the following formula:
=GetURL(A1)
This post discusses extracting the URL from a cell with a link in it using a custom formula.
This immediately does the job, and add a separate url link column next to the column with the hyperlinked text:
https://howtouseexcel.net/how-to-extract-a-url-from-a-hyperlink-on-excel
Extracting a URL from a hyperlink on Excel -- this worked for me!
If you want to run this operation one time
Open up a new workbook.
Get into VBA (Press Alt+F11)
Insert a new module (Insert > Module)
Copy and Paste the Excel user defined function below (customized function):
Sub ExtractHL()
Dim HL As Hyperlink
For Each HL In ActiveSheet.Hyperlinks
HL.Range.Offset(0, 1).Value = HL.Address
Next
End Sub
Press F5 and click “Run”
Get out of VBA (Press Alt+Q)
You will see a new column with a list of url added to the right.