+ Reply to Thread
Results 1 to 6 of 6

Extend a VBA macro with a hyperlinks table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Extend a VBA macro with a hyperlinks table

    Hello!

    I want to add following functionality to a vba macro. The program collects data from different sheets and writes it into a single sheet. The layout is like this:

    Blank row
    
    Cell A2 - Title for the upcoming block
    Cells A3:L16 - Data block
    
    Blank row
    
    Cell A18 Title
    Cells A19:L55 - Data block
    
    Blank row
    
    etc.
    In total, I have 12 data blocks with titles. There is always a blank line between the data blocks. Now, I want to add hyperlinks to the title cells A2, A18 etc. These hyperlinks should be in the cells N10, N11, N12 and so on. Also, N10 should contain the text information in A2.
    So: if A2 contains the text "Title1", I would want to have a hyperlink in N10 called "Title 1" and jump to A2 when clicking N10.

    It would be great, if the macro would be handle a random number of data blocks, so that I wouldn't have to tell beforehand how many blocks I have.

    Do you have any ideas how to do this? Thank you very much!

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Extend a VBA macro with a hyperlinks table

    Hi excelactuary

    Any chance of a sample workbook depicting your requirement.

    Edit: Not to worry, see if this is what you require:
    Option Explicit
    
    Sub Title_hyperLink()
    Dim rngTo As Range, rngFrom As Range
    Dim lRow As Long
    Dim i As Integer, j As Integer
    Dim LinkText As String
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Set ws = Sheets("Sheet1")
    lRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
    With Sheets("Sheet1")
        j = 10
        For i = 1 To lRow
            If Cells(i, 1).Value = "" Then
                Set rngFrom = ws.Cells(i, 1).Offset(1, 0)
                Set rngTo = ws.Cells(j, 14)
                LinkText = ws.Cells(i, 1).Offset(1, 0).Text
                rngFrom.Parent.Hyperlinks.Add Anchor:=rngTo, Address:="", _
                SubAddress:="'" & rngTo.Parent.Name & "'!" & rngFrom.Address(), _
                TextToDisplay:=LinkText
                j = j + 1
            End If
        Next i
    End With
    Application.ScreenUpdating = False
    End Sub
    Attached Files Attached Files
    Last edited by Sintek; 04-24-2017 at 05:07 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Extend a VBA macro with a hyperlinks table

    Hello sintek!

    Thank you so much, your code does exactly what I wanted. In the future, I will post a workbook sample.

    One more question: if I want to add custom text in the cell N9, what would I add to the code?

    Edit:

    Got it:

    Dim TxtRng  As Range
    Set TxtRng = ws.Range("N9")
        TxtRng.Value = "Text"
    Last edited by excelactuary; 04-24-2017 at 05:35 AM.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Extend a VBA macro with a hyperlinks table

    if I want to add custom text in the cell N9
    ...Don't you mean custom text in N10, N11 etc
    If so change this line of code
    LinkText = ws.Cells(i, 1).Offset(1, 0).Text
    to
    LinkText = "Add your Custom Text between these"
    or do you just want to add a heading in N9.

  5. #5
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Extend a VBA macro with a hyperlinks table

    I just want a heading in N9.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Extend a VBA macro with a hyperlinks table

    add this line
    Cells(9, 14) = "Add your Custom Text between these"
    under
    j = 10
    Glad I could help. thanks for rep points.

+ 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. Auto Extend Table linked with another table
    By azmat119 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2017, 03:51 PM
  2. Auto Extend Table linked with another table
    By azmat119 in forum Excel General
    Replies: 1
    Last Post: 02-09-2017, 02:35 PM
  3. Auto Extend Table linked with another table
    By azmat119 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-09-2017, 06:37 AM
  4. Making Table of Content with hyperlinks in a PDF using a macro of excel
    By biguel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2016, 10:22 AM
  5. Macro to extend a table range
    By qaliq in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2013, 09:38 AM
  6. [SOLVED] remove hyperlinks in macro affected format table
    By rickmeister in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 12:58 PM
  7. I would like to extend hyperlinks across cells
    By venkat in forum Excel General
    Replies: 2
    Last Post: 05-20-2005, 11:06 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