|
本帖最后由 cmo9020 于 2023-1-13 21:42 编辑
TEST1.rar
(180.21 KB, 下载次数: 10)
请导师帮忙一下,原本代码没有加入年查询,变成混在一起目前要修改sub Week () 是周数,
输入年份是在sheet2 A1单元格,
然后把sheet1的相同年份资料给带到sheet2
可以个别查询2022,2023年的周数,去带出sheet1 L列的异常事项
月份和周数代码还有正确解答都在"代码"工作表
月份是修改过后的,可以执行
要是有看不懂地方,希望导师们可以把SHEET2 a4:aa4以下数据做清空去执行代码看看,应该看的出来我说的意思
但周数改不出来
周数代码目前放回春风导师给的原代码
希望以原来代码下去做周数的修改,不然我会很错乱
麻烦请导师帮忙看一下,谢谢各位....我困扰好几天都睡不太着,请各位帮帮忙
Sub WEEK()
Dim d As Object, dc As Object
Dim ar As Variant, br As Variant
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Tt = Timer
With Sheets("Sheet1")
r = .Cells(Rows.count, 1).End(xlUp).Row
ar = .Range("B1:N" & r)
End With
With Sheets("Sheet2")
rs = .Cells(Rows.count, 15).End(xlUp).Row
If rs > 3 Then
.Range("o4:aa" & rs).Borders.LineStyle = 0
.Range("o4:aa" & rs) = 0
End If
u = UBound(ar)
br = .Range("o3:aa" & u)
For j = 2 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
k = 1
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then dc(Trim(ar(i, 1))) = dc(Trim(ar(i, 1))) + 1
If Trim(ar(i, 1)) <> "" And Trim(ar(i, 11)) <> "" Then
t = d(Trim(ar(i, 11)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 11))) = k
t = k
br(k, 1) = ar(i, 11)
End If
lh = d(Trim(ar(i, 1)))
If lh <> "" Then
br(t, lh) = br(t, lh) + 1
End If
End If
Next i
k = k + 1
br(k, 1) = "不良总数"
br(k + 1, 1) = "检验总数"
br(k + 2, 1) = "不良率"
For j = 2 To UBound(br, 2)
br(k, j) = Application.Sum(Application.Index(br, 0, j))
lh = d(Trim(br(1, j)))
br(k + 1, j) = dc(Trim(br(1, j)))
If br(k + 1, j) = 0 Then
br(k + 2, j) = 0
br(k + 1, j) = 0
Else
br(k + 2, j) = br(k, j) / br(k + 1, j)
End If
Next j
.[o3].Resize(k + 2, UBound(br, 2)) = br
.Cells(k + 4, 2).Resize(1, 32).NumberFormatLocal = "0.0%"
.[o3].Resize(k + 2, UBound(br, 2)).Borders.LineStyle = 2
End With
Set d = Nothing
Set dc = Nothing
End Sub
|
|