+ Reply to Thread
Results 1 to 3 of 3

Extract cell reference from hyperlink created by VBA

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Extract cell reference from hyperlink created by VBA

    I have a macro (thank you watersev!) that finds a cell reference in my worksheet based on a search value and returns a clickable hyperlink to send me to that cell in my worksheet.
    What I want is that in my "Start" sheet on cells D9 downwards I want it to look into the hyperlink that is created in C9 downwards, and if that cell reference hyperlinked is less than 190, return the word Premium, and if not then return AP/RP. As per my example in the attached.

    The macro that fires when you hit the search button currently does the following:

    Sub test()
    
    Dim lrow As Long, n As Long, i As Long, mainsh As Worksheet, c As Range, rcount As Long
    Dim search_val, Sh, resultarr, addrarr, temparr, cl
    Dim shname As String, firstAddress As String, addrstr As String, resultstr As String
    
    lrow = Cells(Rows.Count, 2).End(xlUp).Row
    If lrow > 9 Then Range("b9:c" & lrow).Clear
    
    If Range("a3") = "" Then Exit Sub
    
    search_val = Range("a3")
    
    Application.ScreenUpdating = 0
    Application.EnableEvents = 0
    
    Set mainsh = Sheets("Start")
    
    For Each Sh In ActiveWorkbook.Sheets
        If InStr("GraphsStartSummary", Sh.Name) = 0 Then
            If Sh.Visible = True Then
                lrow = Sh.Cells(Rows.Count, "c").End(xlUp).Row
                If lrow > 16 Then
                    shname = Sh.Name
                    With Sh.Range("c17", Sh.Cells(Rows.Count, "c").End(xlUp))
                        iflag = Sh.Rows(17).Hidden
                        If iflag = True Then Sh.Rows(17).Hidden = False
                        Set c = .Find("*" & search_val & "*", , xlValues, xlWhole)
                        If Not c Is Nothing Then
                            firstAddress = c.Address
                            Do
                                If addrstr = "" Then addrstr = "'" & shname & "'!" & c.Address Else addrstr = addrstr & "|'" & shname & "'!" & c.Address
                                If resultstr = "" Then resultstr = c.Value & "~" & shname Else resultstr = resultstr & "|" & c.Value & "~" & shname
                                Set c = .FindNext(c)
                            Loop While Not c Is Nothing And c.Address <> firstAddress
                        End If
                        Sh.Rows(17).Hidden = iflag
                    End With
                End If
            End If
        End If
    Next
    
    If resultstr <> "" Then
        
        resultarr = Split(resultstr, "|")
        addrarr = Split(addrstr, "|")
        
        rcount = UBound(resultarr)
        ReDim result(0 To rcount, 0 To 1)
    
        For i = 0 To rcount
            temparr = Split(resultarr(i), "~")
            result(i, 0) = temparr(0)
            result(i, 1) = temparr(1)
        Next
        
        With mainsh.Range("b9:c" & rcount + 9)
            .NumberFormat = "@"
            .Value = result
            For Each cl In .Offset(, 1).Resize(, 1)
                cl.Hyperlinks.Add cl, "", addrarr(n), , cl.Value
                n = n + 1
            Next
        End With
        
    End If
    
    Application.EnableEvents = 1
    Application.ScreenUpdating = 1
    
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Extract cell reference from hyperlink created by VBA

    is this not possible?

  3. #3
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Extract cell reference from hyperlink created by VBA

    sorry to be a pain - but noone?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Using Dynamic cell reference in cell formula created by VBA
    By grazian2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2013, 11:05 AM
  2. How to hyperlink cell value to userform created worksheet?
    By jwichern1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2011, 12:37 PM
  3. Link/Reference to a Cell on a Worksheet That Hasn't Been Created...
    By bpowers in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2009, 12:01 AM
  4. Hyperlink created from cell content
    By Endorphin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2008, 04:06 AM
  5. [SOLVED] script to hyperlink and reference a cell value in the hyperlink
    By Natasha D. in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2006, 02:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1