Quick Question with Function help

Rockhopper3

Board Regular
Joined
Apr 11, 2006
Messages
131
Code:
Function CountBold(r As Range) As Long
  Dim c As Range
  
  Application.Volatile
  For Each c In r
    If c.Font.Bold Then CountBold = CountBold + 1
  Next c
End Function

So I am using the above code to increase the value of column I by one when the cell in the same row in column C is double clicked. This all works great, the only problem is the same thing is happening when I double click a cell in column B. I need this function to only work when a cell in column C is double clicked. Any help would be most appreciated.
Cheers.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hello,

The UDF is not able to recognize a double click.

Would you paste the worksheet module code...I am thinking the amends need to happen there before it gets to this function.
 
Upvote 0
Apologies to everyone. I posted the wrong bit of code. The code I meant to post is below.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Intersect(Target, Range("B:E")) Is Nothing Then
        Cancel = True   'Prevent going into Edit Mode
        Exit Sub
    End If

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    With Target
        .Font.Name = "Marlett"
        .Font.Size = 14
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Value = "a"
    End With

 Range("I" & Target.Row).Select
    ActiveCell.FormulaR1C1 = "=TEXT(R3C37+30,""mmm"")"
 Range("I" & Target.Row).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
Range("A" & Target.Row).Select
    Application.EnableEvents = True
    Application.ScreenUpdating = True
 
Upvote 0
I didn't really try to disect what you have...

I did add a few lines:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_BeforeDoubleClick(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range, Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)<br><br><SPAN style="color:#00007F">Dim</SPAN> Changed <SPAN style="color:#00007F">As</SPAN> Range<br><br><SPAN style="color:#00007F">Set</SPAN> Changed = Intersect(Target, Range("C:C"))<br><br><SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Changed <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>MsgBox 1<br>    <SPAN style="color:#00007F">If</SPAN> Intersect(Target, Range("B:E")) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        Cancel = <SPAN style="color:#00007F">True</SPAN>   <SPAN style="color:#007F00">'Prevent going into Edit Mode</SPAN><br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br>    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <br>    <SPAN style="color:#00007F">With</SPAN> Target<br>        .Font.Name = "Marlett"<br>        .Font.Size = 14<br>        .HorizontalAlignment = xlCenter<br>        .VerticalAlignment = xlCenter<br>        .Value = "a"<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br> Range("I" & Target.Row).Select<br>    ActiveCell.FormulaR1C1 = "=TEXT(R3C37+30,""mmm"")"<br> Range("I" & Target.Row).Select<br>    Selection.Copy<br>    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<br>        :=False, Transpose:=<SPAN style="color:#00007F">False</SPAN><br>    Application.CutCopyMode = False<br><br>Range("A" & Target.Row).Select<br>    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top