How would I enter this worksheet formula in VBA? Hyperlink within workbook

robertgama

Board Regular
Joined
May 4, 2011
Messages
189
After I process data, I'm putting links back to the original data so the user can fix the values if there were errors.


Here is the worksheet formula in column F and in this case row 6:

Code:
=IF(E6="Requires Fix",HYPERLINK(aaGetHyperlinkLocation(Clients!H2),Clients!H2),"")

aaGetHyperlinkLocation is just a UDF to return a properly formatted location for the hyperlink function from a range.

I would like to be able to do the same with VBA, resulting in a hyperlink the the cells back to 'Clients!H2'. How would that be accomplished with VBA?

Thanks,

Rob.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Rob

To enter that formula in a cell.
Code:
Range("A2").Formula ="=IF(E6=""Requires Fix"",HYPERLINK(aaGetHyperlinkLocation(Clients!H2),Clients!H2),"""")"

If that's not what you want you'll need to explain a bit more, for example what exactly does aaGetHyperLinkLocation return?
 
Upvote 0
Thanks Norie, I'll test that out.

I'll post what the helper function returns (just the format that the function is expecting):

Code:
Public Function aaGetHyperlinkLocation(myRange As Range) As String

        If aaGetSheetName(myRange) = Application.ActiveSheet.Name Then
            aaGetHyperlinkLocation = "[" + aaGetFileName() + "]" + myRange.Address
        Else
            aaGetHyperlinkLocation = "[" + aaGetFileName() + "]'" + aaGetSheetName(myRange) + "'!" + myRange.Address
        End If
    
End Function

Thanks again,

Rob.
 
Upvote 0
Thanks again. It worked out nicely.

Since I already had the previous columns' value in an array, I did the following:

Code:
For j = 1 To numRecords
        'many more lines of code...

        If fixedProvinces(j, 1) = "Requires Fix" Then
            hyperlinkFixProvinces(j, 1) = "=HYPERLINK(aaGetHyperlinkLocation(Clients!H" & CStr(j + 1) & "),Clients!H" & CStr(j + 1) & ")"
        End If

        'many more lines of code...
       
Next j
'...
Range("F" + CStr(startRow) + ":F" + CStr(lastRow)).Formula = hyperlinkFixProvinces
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top