VBA: Double click choices from a range

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,362
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm using a doubleclick event with the code below and all works well with the range of G2:G5.

At times the range could be longer, but not sure how to rearrange this to accomodate for say a range of G2:G10.

The range contains text.

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    If Target.Address = "$H$6" Then
        If Target.Value = Sheets(MyCtrlPanel).Range("G2") Then
            Target.Value = Sheets(MyCtrlPanel).Range("G3")
        ElseIf Target.Value = Sheets(MyCtrlPanel).Range("G3") Then
            Target.Value = Sheets(MyCtrlPanel).Range("G4")
        ElseIf Target.Value = Sheets(MyCtrlPanel).Range("G4") Then
            Target.Value = Sheets(MyCtrlPanel).Range("G5")
        ElseIf Target.Value = Sheets(MyCtrlPanel).Range("G5") Then
            Target.Value = Sheets(MyCtrlPanel).Range("G2")
        End If
    End If
[/FONT]
 

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.
How about
Code:
   Dim i As Long

   If Target.Address = "$H$6" Then
      For i = 2 To 10
         If Target.Value = Sheets(MyCtrlPanel).Range("G" & i) Then
            If i < 10 Then
               Target.Value = Sheets(MyCtrlPanel).Range("G" & i + 1)
            Else
               Target.Value = Sheets(MyCtrlPanel).Range("G2")
            End If
         End If
      Next i
   End If
 
Upvote 0
Hi Fluff and thank you for the help.

That seems to just cycle thru all the choices with one double click. I was looking for the user to cycle thru the choices one by one as they continue to double click or even just double click once for the next choice.

I had to change the variable to j since [FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]i[/FONT] was already used. Also, A22 will hold the length of the range in column G.

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    Dim j As Long
    Dim jj   As Long: jj = Sheets("ControlPanel").Range("A22").Value[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]    If Target.Address = "$H$6" Then
       For j = 2 To jj
          If Target.Value = Sheets(MyCtrlPanel).Range("G" & j) Then
             If j < jj Then
                Target.Value = Sheets(MyCtrlPanel).Range("G" & j + 1)
             Else
                Target.Value = Sheets(MyCtrlPanel).Range("G2")
             End If
          End If
       Next j
    End If[/FONT]
 
Upvote 0
I missed a bit
Code:
             End If
             [COLOR=#ff0000]Exit For[/COLOR]
          End If
       Next j
 
Last edited:
Upvote 0
Thank you Fluff. That works wonderful.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,432
Messages
6,119,468
Members
448,900
Latest member
Fairooza

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