Я не уверен, что вам нужно делать, но после анализа вашего кода, я предполагаю, что вы хотите что-то вроде этого кода ниже.Процедура ищет базовые точки полюсов и копирует их данные на лист Data
, а затем ищет все точки заземления, которые находятся на расстоянии 6 футов от каждой базовой точки полюсов, а также копирует их данные на лист Data
.Я использовал функцию fnDistance
для расчета расстояния между точками.
Sub prcEmbedSlope()
Dim wbWorkbook As Workbook
Dim intBaseRow, intGroundRow As Integer
Dim intTargetRow As Integer
Dim dblXBase, dblYBase As Double
Dim dblXGround, dblYGround As Double
Dim dblDistance As Double
Set wbWorkbook = Application.ThisWorkbook
intTargetRow = 1
'First loop (looking for pole base points)
For intBaseRow = 2 To 15
If wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 3).Value = 311 Then
dblXBase = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 4).Value
dblYBase = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 5).Value
'Copy pole base points data to the 2nd sheet
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 1).Value = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 1).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 3).Value = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 3).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 4).Value = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 4).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 5).Value = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 5).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 6).Value = wbWorkbook.Worksheets("Survey Input").Cells(intBaseRow, 6).Value
intTargetRow = intTargetRow + 1
'Second loop (looking for ground points within 6 ft. distance)
For intGroundRow = 2 To 15
If wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 3).Value = 200 Then
dblXGround = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 4).Value
dblYGround = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 5).Value
dblDistance = fnDistance(dblXGround, dblYGround, dblXBase, dblYBase)
If dblDistance < 6 Then
'Copy ground points data to the 2nd sheet
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 1).Value = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 1).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 3).Value = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 3).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 4).Value = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 4).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 5).Value = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 5).Value
wbWorkbook.Worksheets("Data").Cells(intTargetRow, 6).Value = wbWorkbook.Worksheets("Survey Input").Cells(intGroundRow, 6).Value
intTargetRow = intTargetRow + 1
End If
End If
Next intGroundRow
End If
Next intBaseRow
End Sub
Function fnDistance(ByVal dblXG As Double, ByVal dblYG As Double, _
ByVal dblXB As Double, ByVal dblYB As Double) As Double
fnDistance = Sqr((dblXG - dblXB) ^ 2 + (dblYG - dblYB) ^ 2)
End Function