|
'自动加层位保存
Sub zdjcw11()
Dim i, j, n, k, l As Integer
Dim d As Date
Dim rng As Range
Application.ScreenUpdating = False
k = Sheets("表1").Range("a65536").End(xlUp).Row
For l = 2 To k
Sheet1.Range("q1") = k
Set rng = Sheets("表1").Range("a" & l)
For i = 2 To 23086
If Sheets("表2").Cells(i, 5) = rng Then
'Sheets("表2").Cells(i, 5).Interior.Color = vbBlue
GoTo aaa
End If
Next i
aaa: '以深度数据取层位数据
For n = 0 To 23
If rng.Offset(0, 2).Value > Sheets("表2").Cells(i + n, 5).Offset(3, 0).Value And rng.Offset(0, 2).Value < Sheets("表2").Cells(i + (n + 1), 5).Offset(3, 0).Value Then
Sheets("表2").Cells(i + (n + 1), 5).Offset(3, -1).Copy rng.Offset(0, 5)
'下面代码表示,如果底深左侧层位为空值,则取向左取一格
If Sheets("表2").Cells(i + (n + 1), 5).Offset(3, -1) = "" Then
Sheets("表2").Cells(i + (n + 1), 5).Offset(3, -2).Copy rng.Offset(0, 5)
End If
If rng.Offset(0, 5) <> "" Then
Exit For
End If
End If
Next
Next
Application.ScreenUpdating = True
MsgBox ("共统计了" & l & "口井")
End Sub
____________________________________
这段代码 怎么有时候可以运行成功,有时候会报错呢,错误见图片,请大神帮忙看看。
|
|