ComboBox not loop around

satoshi_sd

New Member
Joined
Nov 5, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I have a ComboBox (active x) with other VBA running which has loop on and every time I clicked on the dropdown of the combobox, it will loop around and starts again from the first item (in other word I couldn't even scroll/drag down the list. Is there a way to fix this?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi satoshi_sd,

maybe you should share your code...

Holger
 
Upvote 0
2 codes here, 1st one - I'm making a running live clock. 2nd one - I want to make a selectable timezone by choosing from dropdownlist
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Hour As Boolean
Hour = Not (Hour)
Do While Hour = True
DoEvents
Range("B2") = Now()
Loop
End Sub

Private Sub ComboBox1_GotFocus()
    ComboBox1.ListFillRange = "DropDownList"
    Me.ComboBox1.DropDown
End Sub
 
Upvote 0
Hi satoshi_sd,

if you want to choose from a dropdownlist to my opinion you should no use Worksheet_SelectionChange which gets fired each time the cursor is moved around in the sheet.

Are you looking for something like this:

Sample Running Time in Cell 230202.xlsm
ABCDEFGHIJKLMN
1Namerelated
2UTC-1
3Berlin0<-- time from computer
4BerlinEST-6
511:40:43local timeJST8
6
7
Sample Running Time
Cells with Data Validation
CellAllowCriteria
B4List=myTimeList


Code in a standard module (I renamed the module to mod_RunningTimeCell, if newly added should be ModuleX where X stands for a running number):

VBA Code:
Public gdteNextStart As Date                    'next starting time for macro
Public gdblTime As Double                       'time difference from chiosen timezone to computer time

Public Const gdteTimeSpan As Date = "00:00:01"  'time to update macro
'

Sub StartRunningTimeInCell()
  Worksheets("Sample Running Time").Range("A5") = Format(Time + gdblTime, "hh:mm:ss")
  gdteNextStart = Now + gdteTimeSpan
  Application.OnTime gdteNextStart, "StartRunningTimeInCell"
End Sub

Private Sub StopRunningClock()
  On Error Resume Next
  Application.OnTime EarliestTime:=gdteNextStart, _
                      Procedure:="StartRunningTimeInCell", _
                      Schedule:=False
End Sub


Code behind the sheet with the running clock (for my sample Worksheets("Sample Running Time"):

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  gdblTime = TimeSerial(WorksheetFunction.VLookup(Range("B4"), Range("myTimeList").CurrentRegion, 2, 0), 0, 0)
End Sub


Code in ThisWorkbook:

VBA Code:
Private Sub Workbook_Open()
  StartRunningTimeInCell
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  On Error Resume Next
  Application.OnTime EarliestTime:=gdteNextStart, _
                      Procedure:="StartRunningTimeInCell", _
                      Schedule:=False
End Sub

Ciao,
Holger
 
Upvote 0
Solution
Hi satoshi_sd,

if you want to choose from a dropdownlist to my opinion you should no use Worksheet_SelectionChange which gets fired each time the cursor is moved around in the sheet.

Are you looking for something like this:

Sample Running Time in Cell 230202.xlsm
ABCDEFGHIJKLMN
1Namerelated
2UTC-1
3Berlin0<-- time from computer
4BerlinEST-6
511:40:43local timeJST8
6
7
Sample Running Time
Cells with Data Validation
CellAllowCriteria
B4List=myTimeList


Code in a standard module (I renamed the module to mod_RunningTimeCell, if newly added should be ModuleX where X stands for a running number):

VBA Code:
Public gdteNextStart As Date                    'next starting time for macro
Public gdblTime As Double                       'time difference from chiosen timezone to computer time

Public Const gdteTimeSpan As Date = "00:00:01"  'time to update macro
'

Sub StartRunningTimeInCell()
  Worksheets("Sample Running Time").Range("A5") = Format(Time + gdblTime, "hh:mm:ss")
  gdteNextStart = Now + gdteTimeSpan
  Application.OnTime gdteNextStart, "StartRunningTimeInCell"
End Sub

Private Sub StopRunningClock()
  On Error Resume Next
  Application.OnTime EarliestTime:=gdteNextStart, _
                      Procedure:="StartRunningTimeInCell", _
                      Schedule:=False
End Sub


Code behind the sheet with the running clock (for my sample Worksheets("Sample Running Time"):

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  gdblTime = TimeSerial(WorksheetFunction.VLookup(Range("B4"), Range("myTimeList").CurrentRegion, 2, 0), 0, 0)
End Sub


Code in ThisWorkbook:

VBA Code:
Private Sub Workbook_Open()
  StartRunningTimeInCell
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  On Error Resume Next
  Application.OnTime EarliestTime:=gdteNextStart, _
                      Procedure:="StartRunningTimeInCell", _
                      Schedule:=False
End Sub

Ciao,
Holger
Thank you, do you mind sharing your template? I can't seem to get it working.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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