0
ユーザーフォームのリストボックスの値を、同じユーザーフォームの別のリストボックスの値を変更したときに動的に変更する方法を教えてください。私に困っている主な部分はlstMonthです。 lstMonthの値は、最初のリストボックスに表示される異なるシートのデータと相関する月と等しくなければなりません。私はフォームとデータの写真を提供して、これ以降すべてがより多くなるようにします。 リストボックスの値をワークシートで動的に変更する
コード
Option Explicit
Private Sub cmdCalc_Click()
'declare variables and assign address to rngData variable
Dim strId As String, intRow As Integer, intNumSales As Integer, curSales As Currency
Dim rngData As Range
Set rngData = Application.Workbooks("t13-ex-e4d.xls").Worksheets("jan").Range("a3").CurrentRegion
'assign selected list box item to strId variable
strId = lstId.Value
'locate first occurrence of ID
intRow = 2
Do Until rngData.Cells(RowIndex:=intRow, columnindex:=4).Value = strId
intRow = intRow + 1
Loop
'accumulate and count salesperson's sales, stop when loop encounters different ID
Do While rngData.Cells(RowIndex:=intRow, columnindex:=4).Value = strId
curSales = curSales + rngData.Cells(RowIndex:=intRow, columnindex:=3).Value
intNumSales = intNumSales + 1
intRow = intRow + 1
Loop
'display appropriate amount
If optTotal.Value = True Then
lblAnswer.Caption = Format(expression:=curSales, Format:="currency")
Else
lblAnswer.Caption = Format(expression:=curSales/intNumSales, Format:="currency")
End If
End Sub
Private Sub cmdCancel_Click()
'close custom dialog box
Unload frmSalesCalc
End Sub
Private Sub UserForm_Initialize()
lstMonth.Value = Application.Workbooks("T13-EX-E4D.xls").ActiveSheet.Range("b3").CurrentRegion
End Sub
私は本当に質問を理解していない、どのような月のリストボックスにする必要がありますか?すべての月があるか、または営業担当者が販売しているすべての月? –
月リストボックスは、ブック内のすべてのワークシートの名前と同じにする必要があります。今は3つ(2月、3月、4月)ですが、誰かが5月を追加すると、自動的にリストボックスに入れることが必要になります。それが動作したら、月の左側のリストボックスは、選択されているワークシート上の販売IDに変更する必要があります。私はそれが助けて欲しい! –