I undertook a few computer programming projects many decades ago & am returning to try to write some VBA in Excel to enable us to play bridge with another couple during the lockdown. The choice of Excel is to enable one of the others to enter the decisions of their disabled spouse. I have declared a Public variable, ‘RngChoice’, that successfully stores the non-contiguous cells to select from (at least for the first bid!) but DoubleClick refuses to operate. I have probably made a naïve mistake but I have made strenuous efforts to find a solution online as well as experimenting with possible solutions myself. During development, the loop calling DoubleClick should be passed through just once but the pass is not completed. The loop code is:
Do
' Start with NB always an option
Set RngChoice = Cells(5, 6)
' Set choice area if no bids been made or calculates RngChoice
If MaxBid = 0 Then Set RngChoice = Union(Range(Cells(1, 1), (Cells(7, 5))), RngChoice) Else BidArea
Call Worksheet_BeforeDoubleClick(Nothing, False)
…….
Loop Until NoBidCount = 4 Or (MaxBid > 0 And NoBidCount = 3)
The DoubleClick procedure currently includes a checking message which correctly reports that ‘RngChoice’ is “$A$1:$E$7,$F$5”; the next line fails, whether or not the message line is included. The procedure is fairly standard:
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
MsgBox RngChoice.Address
If Not Intersect(Target, RngChoice) Is Nothing Then
Target.Interior.Color = vbGreen
MsgBox "You clicked in Double Click Range!"
Cancel = True
End If
End Sub
I have tried experimenting with putting this procedure elsewhere but it is currently sitting with the other procedures for the sheet I’m working on.
The process freezes at the “If Not Intersect ….” line. The stepping-through, checking process confirms it is that line causing the problem, producing the message, “Run-time error ‘5’: Invalid procedure call or argument.”
Replacing ‘RngChoice’ with simple ranges in various formats (e.g. Cells(1, 1), Range(“A1”), Range(“A” & 1)) produces the same failure.
Any help would be much appreciated.
Do
' Start with NB always an option
Set RngChoice = Cells(5, 6)
' Set choice area if no bids been made or calculates RngChoice
If MaxBid = 0 Then Set RngChoice = Union(Range(Cells(1, 1), (Cells(7, 5))), RngChoice) Else BidArea
Call Worksheet_BeforeDoubleClick(Nothing, False)
…….
Loop Until NoBidCount = 4 Or (MaxBid > 0 And NoBidCount = 3)
The DoubleClick procedure currently includes a checking message which correctly reports that ‘RngChoice’ is “$A$1:$E$7,$F$5”; the next line fails, whether or not the message line is included. The procedure is fairly standard:
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
MsgBox RngChoice.Address
If Not Intersect(Target, RngChoice) Is Nothing Then
Target.Interior.Color = vbGreen
MsgBox "You clicked in Double Click Range!"
Cancel = True
End If
End Sub
I have tried experimenting with putting this procedure elsewhere but it is currently sitting with the other procedures for the sheet I’m working on.
The process freezes at the “If Not Intersect ….” line. The stepping-through, checking process confirms it is that line causing the problem, producing the message, “Run-time error ‘5’: Invalid procedure call or argument.”
Replacing ‘RngChoice’ with simple ranges in various formats (e.g. Cells(1, 1), Range(“A1”), Range(“A” & 1)) produces the same failure.
Any help would be much appreciated.