|
楼主 |
发表于 2024-3-16 07:48
|
显示全部楼层
Private Sub UserForm_Initialize() '初始设计
ComboBox1.Clear '清空内容
i = Sheet16.Range("C300").End(3).Row '从《客户名册》中提取最后行号
For S = 3 To i '设置范围:从第三行开始到最后行号
If WorksheetFunction.CountIf(Sheet16.Range("C3:C" & S), Sheet16.Range("C" & S)) = 1 Then '规避重复值
ComboBox1.AddItem Sheet16.Range("C" & S) '把C列数据导入ComboBox,生成下拉框
End If
Next S
End Sub
Sub 表内统计()
On Error Resume Next
For i = 0 To ListBox1.ListCount - 1
t = ListBox1.List(i, 7)
S = Val(t)
SB1 = SB1 + S
Next
TextBox2.Value = SB1
'----------------------------------------
For f = 0 To ListBox1.ListCount - 1
c = ListBox1.List(f, 9)
d = Val(c)
SB2 = SB2 + d
Next
TextBox3.Value = SB2
'----------------------------------------
TextBox4.Value = Val(TextBox2) - Val(TextBox3)
'----------------------------------------
For f = 0 To ListBox1.ListCount - 1
c = ListBox1.List(f, 5)
d = Val(c)
SB3 = SB3 + d
Next
TextBox5.Value = SB3
End Sub
Private Sub ComboBox1_Change()
Dim i&, j%, t%, myStr$, k&, n$, P$, S$
Dim LG As Boolean, ARR1()
With Sheets("车辆名录")
Myr = .[B10000].End(3).Row
arrsj = .Range("B4:L" & Myr)
End With
Me.ListBox1.Clear
myStr = UCase(Me.ComboBox1.Value)
For i = 1 To Len(myStr)
If Asc(Mid$(myStr, i, 1)) < 0 Then LG = True: Exit For
Next
tr = 1
ReDim ARR1(1 To Myr, 1 To 11)
ARR1(1, 1) = "日期"
ARR1(1, 2) = "客户"
ARR1(1, 3) = "部首和件号"
ARR1(1, 4) = "单位"
ARR1(1, 5) = "产品名称"
ARR1(1, 6) = "数量"
ARR1(1, 7) = "销售单价"
ARR1(1, 8) = "销售金额"
ARR1(1, 9) = "单位成本"
ARR1(1, 10) = "合计成本"
For R = 1 To UBound(arrsj)
For c = 1 To UBound(arrsj, 2)
If arrsj(R, c) Like "*" & ComboBox1 & "*" Then
tr = tr + 1
ARR1(tr, 1) = Format(arrsj(R, 1), "YYYY-MM-DD")
ARR1(tr, 2) = arrsj(R, 2)
ARR1(tr, 3) = arrsj(R, 3)
ARR1(tr, 4) = arrsj(R, 4)
ARR1(tr, 5) = arrsj(R, 5)
ARR1(tr, 6) = arrsj(R, 6)
ARR1(tr, 7) = arrsj(R, 7)
ARR1(tr, 8) = arrsj(R, 8)
ARR1(tr, 9) = arrsj(R, 9)
ARR1(tr, 10) = arrsj(R, 11)
'ARR1(tr, 11) = Arrsj(r, 11)
Exit For
End If
Next
Next
Me.ListBox1.List = ARR1
表内统计
|
|