+ Reply to Thread
Results 1 to 7 of 7

Run a Macro By Clicking a Named Range

Hybrid View

  1. #1
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Run a Macro By Clicking a Named Range

    OK. I saw your original had ".Offset(0,0)" which is superfluous but perhaps this:

    Private StartCell As Range
    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    
    If Target.SubAddress <> StartCell.Address Then Exit Sub
    
    If Range("A13").EntireRow.Hidden Then
        Range("13:64").EntireRow.Hidden = False
        StartCell.Value = "See Less"
    Else
        Range("13:64").EntireRow.Hidden = True
        StartCell.Value = "Please Click here to see more"
    End If
    
    End Sub
    Public Sub HideRows()
    
    With ThisWorkbook.Worksheets("Bible")
        Set StartCell = .Cells(.Rows.Count, "J").End(xlUp).Offset(1, 0)
        StartCell.Value = "Please Click here to see more"
        .Range("13:64").EntireRow.Hidden = True
        .Hyperlinks.Add Anchor:=StartCell, Address:="", SubAddress:=StartCell.Address, TextToDisplay:=StartCell.Text, ScreenTip:="Click Here"
    End With
    
    Application.EnableEvents = True
    
    End Sub
    Make sure this is in the "Bible" sheet code window and not a separate module.

    WBD
    Office 365 on Windows 11, looking for rep!

  2. #2
    Forum Contributor
    Join Date
    06-30-2014
    Location
    London, England
    MS-Off Ver
    365 & 2010
    Posts
    107

    Re: Run a Macro By Clicking a Named Range

    Works Perfectly to an extent.

    How do I add a lastrow to a private function as I have always used Option Explicit as this range changes and how do I call it from a Module?

    I have this so far in a User Module

    '<----COUNT VALUES IN COLUMN J AND IF GREATER THAN 10
        If Range("J:J").SpecialCells(xlCellTypeConstants, xlTextValues).Cells.Count > 10 Then
        Call HideRows
        Else
        Bible.Rows("13:64").EntireRow.Hidden = False
        End If
    but I'm getting a sub or function error not defined.

    I moved it to a Module and the Hyperlink then doesn't work. But you did say not to put in a separate module so I never expected any different.

    Sorry

+ 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. Adjust existing macro to pick up specific named worksheet and copy to named range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2017, 12:03 PM
  2. Show column to left of named range when clicking hyperlink
    By Crispld in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-31-2014, 06:48 PM
  3. Macro to run one formula for range of cells by clicking on cell
    By christopheralan88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2014, 02:50 PM
  4. excel macro range define to another sheet / named range
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 10:25 AM
  5. Replies: 0
    Last Post: 08-08-2012, 01:02 PM
  6. Replies: 3
    Last Post: 06-04-2011, 10:56 AM
  7. Macro code to change cell range to named range
    By Orlic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2008, 11:51 AM

Tags for this Thread

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