|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
最近做一个查询的界面,做了一个控件,但是数组那边一直报错,检查了很久都没有搞定,请大神帮忙看看,指出我的错误。感激涕零啊....!!!!
Sub test()
Dim ctlLabel As MSForms.Label 'Label控件变量
Dim shtData As Worksheet '数据工作表
Dim rowData As Long '数据记录号
Dim arrData '数据数组
Dim arrResult '结果数组
Dim arrLine '客户名称数组
Dim arrNo '商品型号数组
Dim sLine As String '客户名称
Dim sNo As String '商品型号
Dim rowN As Long '结果行号
Dim colN As Long '结果列号
Dim i As Long '循环变量
Dim skey As String '关键字
Dim shtQuery As Worksheet '查询表
Dim j As Long '行/列序号
Dim rngFind As Range
Set shtQuery = Sheet6
Set shtData = Sheet5
'查询关键字
skey = shtQuery.Range("B6").Value & shtQuery.Range("C6").Value & shtQuery.Range("D6").Value
shtQuery.Range("B7").Value = shtQuery.Range("B6").Value & shtQuery.Range("C6").Value & shtQuery.Range("D6").Value
skey = shtQuery.Range("B7").Value
With shtData
If rngFind Is Nothing Then
Set rngFind = .Range("A1")
End If
Set rngFind = .Cells.Find(skey, rngFind, lookat:=xlWhole)
If rngFind Is Nothing Then
MsgBox ("无匹配数据......")
Else
j = 3
Do
If j = shtData.Range("A1").CurrentRegion.Rows.Count + 1 Then Exit Do
If .Range("H" & j).Value = skey Then
.Range("R" & j).Value = .Range("N" & j).Value
Else
.Range("R" & j).Value = 0
End If
j = j + 1
Loop
End If
colN = shtData.Range("A1").CurrentRegion.Columns.Count + 2
.Columns(6).Copy .Columns(colN)
.Columns(colN).RemoveDuplicates 1, xlYes
arrLine = .Cells(3, colN).CurrentRegion
.Columns(10).Copy .Columns(colN)
.Columns(colN).RemoveDuplicates 1, xlYes
arrNo = .Cells(3, colN).CurrentRegion
arrData = shtData.Range("A1").CurrentRegion.Value
.Columns(colN).Delete
End With
ReDim arrResult(1 To UBound(arrLine), _
1 To UBound(arrNo))
For rowData = 3 To UBound(arrData)
sLine = arrData(rowData, 6)
sNo = arrData(rowData, 10)
For i = 2 To UBound(arrLine)
If sLine = arrLine(i, 1) Then
rowN = i
Exit For
End If
Next
For i = 2 To UBound(arrNo)
If sNo = arrNo(i, 1) Then
colN = i
Exit For
End If
Next
arrResult(rowN, colN) = _
arrResult(rowN, colN) + arrData(rowData, 18) ----- 这句话一直报错,
Next rowData
For rowN = 3 To UBound(arrLine)
arrResult(rowN, 1) = arrLine(rowN, 1)
Next rowN
For colN = 3 To UBound(arrNo)
arrResult(1, colN) = arrNo(colN, 1)
Next colN
With Me
For rowN = 1 To UBound(arrResult, 1)
For colN = 1 To UBound(arrResult, 2)
'添加Label控件,并为其命名唯一名称
Set ctlLabel = .Controls.Add("Forms.Label.1", _
Format(rowN, "00") & Format(colN, "00"))
With ctlLabel
.Caption = arrResult(rowN, colN)
.Height = 20
.Width = 50
.Top = rowN * 20 - 10
.Left = colN * 50 - 40
If rowN = 1 Or colN = 1 Then
.Font.Bold = True
.ForeColor = RGB(0, 0, 255)
End If
End With
Next colN
Next rowN
.Height = UBound(arrResult, 1) * 20 + 40
.Width = UBound(arrResult, 2) * 50 + 20
.Caption = "个人查询结果"
End With
End Sub
生 产 数 据 库 | 姓名 | 生产日期 | 输入时间 | 班次 | 班别 | 线别 | 机型 | 个人查询 | 班组查询 | 机台号 | 零件头型 | 零件长度 | 工单号 | 生产数量 | 报废数量 | 工单状态 | 备注 | 张三 | 2015/11/11 | 2015/10/23 1:32 | 白班 | A | 4# | 五轴 | 张三2015/11/11五轴 | A2015/11/11 | 1# | AL10 | 8 | Ch8732 | 12341 | 11 | 未完 | | 张三 | 2015/11/12 | 2015/10/23 1:32 | 白班 | A | 5# | 五轴 | 张三2015/11/12五轴 | A2015/11/12 | 2# | AL10 | 8 | Ch8733 | 876545 | 877 | 未完 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
|