+ Reply to Thread
Results 1 to 7 of 7

Before double click event with if statements (Double clicking blank cell stops bdc firing)

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    UK
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Before double click event with if statements (Double clicking blank cell stops bdc firing)

    Hi guys,

    I've got a double click event which I'm having issues with...

    Background:
    I have a worksheet which displays sets of data based on values that have been selected from either of 2 combo boxes (Responsible and Reports to). I then have code which allows the user to double click on certain cells (which contain the name of a Responsible person / the person they are reporting to) which will then display the other set of data based on the range that is double clicked.

    I.e. if a responsible persons data is shown and you double click on the person they are reporting to's name then it will take you to their teams data and vice versa

    It is set up so that it recognizes which set of data is being displayed and whether you have selected a valid range/name

    The problem is that when you double click a blank cell (say by accident) and then select a valid cell with a name in it which would normally run the beforedoubleclick event it doesn't trigger.

    I've included my code below and would really appreciate some help!










    'This will run before a double click
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    'Turns off enableevents
    Application.EnableEvents = False
    Application.ScreenUpdating = False

    'elseif the left 2 characters of the selections address is $B and the font of A5 is bold and the right 2 characters of the selections address is greater than 11 and the selection is not empty then
    If Left(Selection.Address, 2) = "$B" And Range("A5").Font.Bold = True And Right(Selection.Address, 2) > 11 And Not IsEmpty(Selection.Value) Then
    Cancel = True
    ActiveSheet.AutoFilterMode = False
    'set the variable selection1 equal to the selections value
    Selection1 = Selection.Value
    'Count the total number of entries in column C + 7
    TotalRows = WorksheetFunction.CountA(Columns("C")) + 7

    'Clears any existing Data and formatting
    Range("B11:N" & TotalRows).Clear
    Range("B11:N" & TotalRows).ClearFormats
    'sets the text of A4:B4 bold
    Range("A4:B4").Font.Bold = True
    'sets the text of A5:B5 not bold
    Range("A5:B5").Font.Bold = False
    'Sets combobox2's selected value to the first value in the list
    Sheets("RIO Review").ComboBox2.ListIndex = 0
    'Sets the selection of combobox1 to the variable selection1
    Sheets("RIO Review").ComboBox1.Value = Selection1
    'sets the text of A4:B4 bold
    Range("A4:B4").Font.Bold = True
    'sets the text of A5:B5 not bold
    Range("A5:B5").Font.Bold = False
    'Runs the responsibleRIO macro (Module 2)
    ResponsibleRIO

    'else if the left 2 characters of the selections address is $B and the right of the selections address is 10 and the selection is not empty then
    ElseIf Left(Selection.Address, 2) = "$B" And Right(Selection.Address, 2) = "10" And Not IsEmpty(Selection.Value) Then
    Cancel = True
    ActiveSheet.AutoFilterMode = False
    'Set the variable selection1 equal to the selection value
    Selection1 = Selection.Value
    'Count the total number of entries in column C + 7
    TotalRows = WorksheetFunction.CountA(Columns("C")) + 7

    'Clears any existing data and formatting
    Range("A10:N" & TotalRows).Clear
    Range("A10:N" & TotalRows).ClearFormats
    'sets the text of A4:B4 not bold
    Range("A4:B4").Font.Bold = False
    'sets the text of A5:B5 bold
    Range("A5:B5").Font.Bold = True
    'Sets combobox1's selected value to the first value in the list
    Sheets("RIO Review").ComboBox1.ListIndex = 0
    'Sets the selection of combobox1 to the variable selection1
    Sheets("RIO Review").ComboBox2.Value = Selection1
    'sets the text of A4:B4 not bold
    Range("A4:B4").Font.Bold = False
    'sets the text of A5:B5 bold
    Range("A5:B5").Font.Bold = True
    'Runs the ReportingRIO macro (Module 2)
    ReportingRIO

    'If the cell that has been double clicked is empty then end
    'If Selection.Value = "" Or IsEmpty(Selection) Then
    'MsgBox "Please select a valid user"
    'Exit Sub
    'Cancel = True
    'end if
    ElseIf Range("B5").Font.Bold = True Then
    Cancel = False
    ReportingRIO
    ElseIf Range("B4").Font.Bold = True Then
    Cancel = False
    ResponsibleRIO
    End If

    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    First off, use the target value rather than selection, this is an Excel.Range data type, so will avail the .row .column properties to you.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    Please Login or Register  to view this content.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    First off, please use code tags.

    Second, you disable events and then don't reset them. There should be:
    Please Login or Register  to view this content.
    at the end of your code.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    UK
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    Thanks for the advice guys, Do you understand what I posted originally?

    If you double click a blank cell (accidentally for instance) the beforedoubleclick event stops working when you try to press on an actual name in a correct range.

    Could you suggest anything?

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    Yes, but you haven't addressed either of my comments. The first is a forum rule, and the second addresses your problem.

  7. #7
    Registered User
    Join Date
    06-26-2014
    Location
    UK
    MS-Off Ver
    MS Office 2010
    Posts
    3

    Re: Before double click event with if statements (Double clicking blank cell stops bdc fir

    Ah my apologies, I didn't realise that would solve my problem!

    Feeling very silly now, thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA double-click item from listview not firing events
    By kriz6912 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2014, 07:39 AM
  2. [SOLVED] Double click event with multiple if statements
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-24-2014, 01:20 AM
  3. Changing cell properties with double click, then revert with another double click
    By mweber2525 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-01-2014, 01:40 PM
  4. Double Click Event Range Cell
    By edgaryp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-03-2013, 09:19 AM
  5. Run an Add in with a double click event on cell
    By rachel.dudley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2013, 10:02 AM

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