+ Reply to Thread
Results 1 to 7 of 7

How can I use VB code to execute macro when double-clicking cell?

  1. #1
    JDay01
    Guest

    How can I use VB code to execute macro when double-clicking cell?

    I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each cell
    in this range, I want to program it so that when a user double-clicks a cell,
    it takes them to the same cell reference on Sheet 2. (i.e. if I click cell
    G45 on the first sheet, it takes me to cell G45 on the second sheet). Can
    anyone help me with the proper code for this action?

  2. #2
    Don Guillett
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    try this idea
    right click sheet tab>view code>insert this>SAVE
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    If Target.Column <> 1 Then Exit Sub
    Application.Goto Sheets("sheet7").Range(Target.Address)
    End Sub

    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    >I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each
    >cell
    > in this range, I want to program it so that when a user double-clicks a
    > cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click
    > cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).
    > Can
    > anyone help me with the proper code for this action?




  3. #3
    Bob Phillips
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    Const WS_RANGE As String = "C10:Z500"
    Dim rng As Range

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
    Set rng = Worksheets("Sheet2").Range(Target.Address)
    Worksheets("Sheet2").Activate
    rng.Select
    End If

    ws_exit:
    Application.EnableEvents = True
    On Error GoTo 0
    End Sub

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    > I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each

    cell
    > in this range, I want to program it so that when a user double-clicks a

    cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click

    cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).

    Can
    > anyone help me with the proper code for this action?




  4. #4
    Don Guillett
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    try this idea
    right click sheet tab>view code>insert this>SAVE
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    If Target.Column <> 1 Then Exit Sub
    Application.Goto Sheets("sheet7").Range(Target.Address)
    End Sub

    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    >I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each
    >cell
    > in this range, I want to program it so that when a user double-clicks a
    > cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click
    > cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).
    > Can
    > anyone help me with the proper code for this action?




  5. #5
    Bob Phillips
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    Const WS_RANGE As String = "C10:Z500"
    Dim rng As Range

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
    Set rng = Worksheets("Sheet2").Range(Target.Address)
    Worksheets("Sheet2").Activate
    rng.Select
    End If

    ws_exit:
    Application.EnableEvents = True
    On Error GoTo 0
    End Sub

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    > I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each

    cell
    > in this range, I want to program it so that when a user double-clicks a

    cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click

    cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).

    Can
    > anyone help me with the proper code for this action?




  6. #6
    Don Guillett
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    try this idea
    right click sheet tab>view code>insert this>SAVE
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    If Target.Column <> 1 Then Exit Sub
    Application.Goto Sheets("sheet7").Range(Target.Address)
    End Sub

    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    >I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each
    >cell
    > in this range, I want to program it so that when a user double-clicks a
    > cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click
    > cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).
    > Can
    > anyone help me with the proper code for this action?




  7. #7
    Bob Phillips
    Guest

    Re: How can I use VB code to execute macro when double-clicking cell?

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
    Boolean)
    Const WS_RANGE As String = "C10:Z500"
    Dim rng As Range

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
    Set rng = Worksheets("Sheet2").Range(Target.Address)
    Worksheets("Sheet2").Activate
    rng.Select
    End If

    ws_exit:
    Application.EnableEvents = True
    On Error GoTo 0
    End Sub

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "JDay01" <JDay01@discussions.microsoft.com> wrote in message
    news:666C7550-51D0-4CA1-A092-17E71C605C2C@microsoft.com...
    > I have a range of cells on Sheet 1 (lets say, range C10:Z500). For each

    cell
    > in this range, I want to program it so that when a user double-clicks a

    cell,
    > it takes them to the same cell reference on Sheet 2. (i.e. if I click

    cell
    > G45 on the first sheet, it takes me to cell G45 on the second sheet).

    Can
    > anyone help me with the proper code for this action?




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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