ExcelVBAマクロでユーザーフォームを初期化しています。コンボボックスにアイテムを入力しようとすると、無限ループに陥りますが、理由はわかりません。これが私のコードです:
Private Sub UserForm_Initialize()
'Populate the combobox with the months
Me.cboCurrMth.SetFocus
Dim cMth As Range
Dim ws As Worksheet
Set ws = Sheet1
For Each cMth In ws.Range("months")
With Me.cboCurrMth
.AddItem cMth.Value
.List(.LineCount - 1, 1) = cMth.Offset(0, 1).Value
End With
Next cMth
End Sub
名前付き範囲「months」には、12行すべてと2列が含まれ、最初の列は整数(1〜12)で、2番目の列は各月の文字列名です。
このループが終了しない理由を誰かが知っていますか?ありがとう。