Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Double click fails to run the code, just selects the cell

If I double click any one of these cell of this line of code, the double click just selects that cell, cursor blinking and cell in the edit mode.

If Target.Address = "$G$14,$G$36,$G$58,$G$80" Then

Each of these cells contain a Vlookup formula:

=IF(ISERROR(VLOOKUP(G7,$AJ$4:$AL$43,3,0)),"",VLOOK UP(G7,$AJ$4:$AL$43,3,0))

and will return a blank cell, or one of these strings, Notes_1, Notes_2 or Notes_3

I think my "If Target.Address =" line is the culprit. I have made the code work with a single "If Range("G14").Value = "Notes_1" Then" statement.

Thanks.
Howard

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim MyIntl As String
Dim MyNote As String

MyNote = Target.Value

If Target.Address = "$G$14,$G$36,$G$58,$G$80" Then
MyIntl = InputBox("Enter your Initials :", "Read Notes.")
If Len(MyIntl) = 0 Then
MsgBox "Enter your initials to read notes", vbCritical
Else
Cells(Rows.Count, "AN").End(xlUp).Offset(1, 0) = MyIntl
Cells(Rows.Count, "AN").End(xlUp) _
.Offset(0, 1) = MyNote & " " & Format(Now(), "dd/MM/yyy hh:mm AMPM")
If Target.Value = "Notes_1" Then MsgBoxNotes_1
If Target.Value = "Notes_2" Then MsgBoxNotes_2
If Target.Value = "Notes_3" Then MsgBoxNotes_3
End If
Cancel = True
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Double click fails to run the code, just selects the cell

Hi Howard,

Am Sun, 5 May 2013 02:44:28 -0700 (PDT) schrieb Howard:

If Target.Address = "$G$14,$G$36,$G$58,$G$80" Then


in an IF-Statement you have to write
If Target.address ="$G$14" or target.address.....
Put it in a Select Case-Statement. There you can write all addresses
with comma as delimiter:

Select Case Target.Address
Case "$G$14", "$G$36", "$G$58", "$G$80"
MyIntl = InputBox("Enter your Initials :", "Read Notes.")
If Len(MyIntl) = 0 Then
MsgBox "Enter your initials to read notes", vbCritical
Else
Cells(Rows.Count, "AN").End(xlUp).Offset(1, 0) = MyIntl
Cells(Rows.Count, "AN").End(xlUp) _
.Offset(0, 1) = MyNote & " " & Format(Now(), "dd/MM/yyy
hh:mm AMPM")
' If Target.Value = "Notes_1" Then MsgBox Notes_1
' If Target.Value = "Notes_2" Then MsgBox Notes_2
' If Target.Value = "Notes_3" Then MsgBox Notes_3
End If
Cancel = True
End Select

If Target.Value = "Notes_1" Then MsgBox Notes_1
If Target.Value = "Notes_2" Then MsgBox Notes_2
If Target.Value = "Notes_3" Then MsgBox Notes_3

will not work for me. What is MsgBoxNotes_1??


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Double click fails to run the code, just selects the cell

Hi Howard,

Am Sun, 5 May 2013 11:57:17 +0200 schrieb Claus Busch:

If Target.Address = "$G$14,$G$36,$G$58,$G$80" Then


in an IF-Statement you have to write
If Target.address ="$G$14" or target.address.....
Put it in a Select Case-Statement. There you can write all addresses
with comma as delimiter:


or you write :
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
If Intersect(Target, Range("G14,G36,G58,G80")) Is _
Nothing Then Exit Sub

So you don't have to write an IF-Statement because the code only will be
fired if the target.address is the expected address.

Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Double click fails to run the code, just selects the cell

Thanks Claus,

I used this statement and works well as you know. However, if I double click on one of the cells that the formula has returned a (blank) "" it evokes the input box. Same with the select case statement. I'm guessing with the formula in the cell it is negating the "...is nothing then" portion of the statement here.

<If Intersect(Target, Range("G14,G36,G58,G80")) Is _
Nothing Then Exit Sub

Here is one of the MsgBoxNotes_1, just a macro displaying a msgbox.

Sub MsgBoxNotes_1()
Dim d As String, e As String, f As String
d = Range("AN5")
e = Range("AN6")
f = Range("AN7")
MsgBox d & vbCr & vbCr & e & vbCr & vbCr & f
End Sub

Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Double click fails to run the code, just selects the cell

Hi Howard,

Am Sun, 5 May 2013 03:52:19 -0700 (PDT) schrieb Howard:

<If Intersect(Target, Range("G14,G36,G58,G80")) Is _
Nothing Then Exit Sub


this will only check the range for correct addresses and has nothing to
do with a formula or a value in a cell. Only if the target is one of the
cells the macro will be fired.
If the inputbox depends on a certain value of the addresses you must
check this in an IF-Statement


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Double click fails to run the code, just selects the cell

On Sunday, May 5, 2013 4:24:02 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Sun, 5 May 2013 03:52:19 -0700 (PDT) schrieb Howard:



<If Intersect(Target, Range("G14,G36,G58,G80")) Is _


Nothing Then Exit Sub




this will only check the range for correct addresses and has nothing to

do with a formula or a value in a cell. Only if the target is one of the

cells the macro will be fired.

If the inputbox depends on a certain value of the addresses you must

check this in an IF-Statement





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Hmmm, that certainly makes sense. I was too hung up on the address part of it.

Thanks, I can make that work for me now that I'm clear on what my issue is.

Regards,
Howard
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Double click fails to run the code, just selects the cell


If the inputbox depends on a certain value of the addresses you must
check this in an IF-Statement



Hmmm, that certainly makes sense. I was too hung up on the address part of it.

Thanks, I can make that work for me now that I'm clear on what my issue is.

Regards,

Howard


Perhaps I spoke to soon...!

Wouldn't this be a logical test of the target cell to exit sub if true?
I still get the cell selected with the below.

On the sheet =Len(G80) returns 0

If Len(Target.Value) = 0 Then Exit Sub

I tested it with this (the commented-out lines) and the msgbox returned 0.


'Dim i As Integer
'i = Len(Target.Value)
'MsgBox I

and tried this, did not work.

If Len(Target.Value) = 0 Then Exit Sub
Cancel = True


Howard
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Double click fails to run the code, just selects the cell

Hi Howard,

Am Sun, 5 May 2013 06:40:56 -0700 (PDT) schrieb Howard:

Wouldn't this be a logical test of the target cell to exit sub if true?
I still get the cell selected with the below.

On the sheet =Len(G80) returns 0

If Len(Target.Value) = 0 Then Exit Sub


Len(Target) gives you the length of the target text. If the formula in
G80 returns an empty string ("") then len = 0.

Which cells should show the inputbox when double-click and which value
should they have to show and with which value the code should go to the
Else-Part?


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell click on one cell selects 2 or 3 cells? Loken Excel Worksheet Functions 2 January 15th 09 11:02 PM
VB CODE for double click? CAPTGNVR[_2_] Excel Programming 4 April 20th 08 03:44 PM
How do I code a cell to display the current date on double-click? George[_27_] Excel Programming 6 December 10th 06 09:26 AM
How to trigger code in Excel add-in after double-click or right-cl Ferko Excel Programming 2 April 19th 06 08:16 AM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM


All times are GMT +1. The time now is 11:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"