|
楼主 |
发表于 2022-12-16 11:50
|
显示全部楼层
高手啊,实在是高,改了这2句,程序全通了。正确程序如下:
Sub 按钮1_单击()
Application.ScreenUpdating = False '冻结屏幕,以防屏幕抖动
'删除上次筛选结果
Sheets("欠注井").Select
Sheets("欠注井").Select
Range("C2:I1000").Select
Selection.ClearContents
'以下为确定表2中的井在表1中设定时间范围内的初始行号和结束行号
Set D = CreateObject("scripting.dictionary")
arr = Sheets("欠注井").[a1].CurrentRegion
brr = Sheets("水井日报").UsedRange
s = CDate(Sheets("欠注井").[i1])
e = CDate(Sheets("欠注井").[k1])
For i = 2 To UBound(brr)
If CDate(brr(i, 1)) >= s And CDate(brr(i, 1)) <= e Then
D(brr(i, 3)) = D(brr(i, 3)) & "," & i
End If
Next i
For i = 2 To UBound(arr)
str1 = arr(i, 2)
If D.exists(str1) Then
brr = Split(D(str1), ",")
arr(i, 3) = brr(1)
arr(i, 4) = brr(UBound(brr))
Else
arr(i, 3) = ""
arr(i, 4) = ""
End If
k1 = arr(i, 3) '表1中单井初始行号
k2 = arr(i, 4) '表1中单井结束行号
Dim k3, k4, k5 As String
Dim jryy, pz, jrsz, pjyy, pjpz, pjsz, qzcd As Variant
k3 = 0: k4 = 0: k5 = 0
jryy = 0: pz = 0: jrsz = 0: pjyy = 0: pjpz = 0: pjsz = 0 '变量赋值0
If k1 = "" Or k2 = "" Then GoTo e2 '表2中的井不在表1中时结束以下计算
For j = k1 To k2
If Sheet2.Cells(i, 2) = Sheet1.Cells(j, 3) And Sheet1.Cells(j, 7) = "开" And Sheet1.Cells(j, 15) > Sheet1.Cells(j, 17) Then k3 = k3 + 1 '求欠注天数
If Sheet2.Cells(i, 2) = Sheet1.Cells(j, 3) And Sheet1.Cells(j, 17) > 0 Then jryy = jryy + Sheet1.Cells(j, 10): pz = pz + Sheet1.Cells(j, 15): jrsz = jrsz + Sheet1.Cells(j, 17) '计算油压、配注和实注
If Sheet2.Cells(i, 2) = Sheet1.Cells(j, 3) And Sheet1.Cells(j, 17) > 0 Then k4 = k4 + 1 '实注水量大于0的行数
If Sheet2.Cells(i, 2) = Sheet1.Cells(j, 3) And Sheet1.Cells(j, 17) = 0 And Sheet1.Cells(j, 7) = "开" Then k5 = k5 + 1 '今日油压大于0的行数
Next j
'计算平均值
If k4 = 0 Then GoTo e1
Sheet2.Cells(i, 3) = k3
pjyy = Round(jryy / k4, 1): Sheet2.Cells(i, 4) = pjyy
pjpz = Round(pz / k4, 1): Sheet2.Cells(i, 5) = pjpz
pjsz = Round(jrsz / k4, 1): Sheet2.Cells(i, 6) = pjsz
e1:
'判断欠注程度,以下为非完全注不进井
If Sheet2.Cells(i, 6) = "关井" Then GoTo e2
If pjpz = 0 Then GoTo e2
qzcd = Application.Round(pjsz / pjpz, 2)
If qzcd > 0 And qzcd <= 0.5 Or pjsz = 0 Then Sheet2.Cells(i, 7) = "严重"
If qzcd > 0.5 And qzcd <= 0.8 Then Sheet2.Cells(i, 7) = "中等"
If qzcd > 0.8 And qzcd <= 0.95 Then Sheet2.Cells(i, 7) = "一般"
If qzcd > 0.95 And qzcd <= 1.2 Then Sheet2.Cells(i, 7) = "合格"
If qzcd > 1.2 Then Sheet2.Cells(i, 7) = "超注"
e2:
'水井日报表中关井或欠注井表中井号在水井日报中没有的井标注为“关井”
If Sheet2.Cells(i, 2) <> Sheet1.Cells(j - 1, 3) Then Sheet2.Cells(i, 3) = "关井": Sheet2.Cells(i, 4) = "关井": Sheet2.Cells(i, 5) = "关井": Sheet2.Cells(i, 6) = "关井"
If Sheet1.Cells(j - 1, 7) = "关" Then Sheet2.Cells(i, 3) = "关井": Sheet2.Cells(i, 4) = "关井": Sheet2.Cells(i, 5) = "关井": Sheet2.Cells(i, 6) = "关井"
Next i
Application.ScreenUpdating = True '结屏幕,此类语句一般成对使用
MsgBox "汇总完成,请查看!", 64, "提示"
End Sub
|
|