Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Double-click on a cell, a message box pops out; how do I do that?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2008, 02:05 AM
blackyroses blackyroses is offline
Freshman
 
Join Date: Sep 2008
Posts: 31
Unhappy Double-click on a cell, a message box pops out; how do I do that?

Hi all.

Thanks to this forum, I got 1 problem solved
HTML Code:
http://www.xtremevbtalk.com/showthread.php?t=300787
What I'd like to ask now is:
If I were to double-click a certain cell, a message box will be popping out. How do I do that in Excel VBA?

Any help would be appreciated
Reply With Quote
  #2  
Old 09-29-2008, 02:24 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Ultimate Contributor

Super Moderator
* Expert *
 
Join Date: Mar 2005
Location: London, UK
Posts: 3,176
Default

Hi,

Conveniently there is an event handler exposed to accomodate this.

In Excel, right click on the worksheet tab of the worksheet containing the cell you want the message box to appear for and select 'view code'. This will open up the worksheet's code module in the VBIDE.

At the top of the code module there are two drop-down boxes. In the left-hand box select 'Worksheet'. In the right-hand box select 'BeforeDoubleClick'. Your code module will be populated with the following procedural skeleton:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

End Sub
This procedure will be executed whenever the user double clicks on the worksheet. 'Target' holds a reference to the cell that was double clicked on so we can use this to check which cell was double clicked and then run code as necessary:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rngCell As Range
    
    'create a reference to the cell we are interested in
    Set rngCell = Range("B2")
    
    'check to see if that cell was double clicked
    If Not Intersect(rngCell, Target) Is Nothing Then
        MsgBox "You double clicked on " & rngCell.Address
    End If
    
End Sub
HTH,
Colin
__________________
Excel: SUMIF() | Excel: Array Formulas | Excel VBA: Deleting Rows

Microsoft MVP - Excel
Reply With Quote
  #3  
Old 10-05-2008, 07:20 PM
blackyroses blackyroses is offline
Freshman
 
Join Date: Sep 2008
Posts: 31
Default

Hi Colin_L, thanks for the codes! I tried to modify it quite a little bit, and it works perfectly fine!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb