Only run code if in column B

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I have the code below in use but something isnt right.

My intention is that when i double click in a cell of column B the code will run BUT should a user double click in another column nothing will happen.

This is what happens.
I double click in column B & the code runs fine like it should.

However if i double click in any other column cell its like ive pressed F2 & now allowing to to make an edit ??
I see the flashing cursor in between the characters as if i was to delete / make a change.

Can you see what ive done wrong.

Thanks


Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim Lastrow As Long
    If ActiveCell.Column = 2 Then
    
    Lastrow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Not Intersect(Target, Range("B8:B" & Lastrow)) Is Nothing Then
        Cancel = True

        If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
        With Worksheets("MCVIN")
            .Activate
            .Range("F7").Value = Target.Value
          
        End With
    Else
    Exit Sub
    
    End If
    MotorcycleBikeInfo.Show
    End If
    
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You have not done anything wrong. The behaviour is just doing what you have in File-Options-Advanced-Allow editing directly in cells
If you don't like that setting then remove the tick from the checkbox and 'OK', or if you only want to disable that setting for this worksheet then put Cancel = True right near the top of your double-click code for this worksheet instead of where you have it now.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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