I'm having a major brain-fart. I keep getting the Compile error: Next without For and it selects this loop:
For COMP2TotalRows = 2 To COMP2RowCount
If Range("L" & COMP2RowCount).Value = "CLOSEST" Then
Range("K" & COMP2RowCount).Value = COMP1Duns
Range("M" & COMP2RowCount).Value = Range("J" & COMP2RowCount).Value
Next COMP2TotalRows
The total Macro is here:
Sub DistanceCalculation()
Dim COMP1StartingPlace, COMP1Duns, COMP1Lat, COMP1Long As String
Dim COMP2RowCount, COMP1RowCount, COMP1TotalRows, COMP2TotalRows As Integer
Worksheets("COMP2 Only").Activate
COMP2RowCount = Range("A65536").End(xlUp).Row
Worksheets("Comp1 Only").Activate
COMP1RowCount = Range("A65536").End(xlUp).Row
For COMP1TotalRows = 2 To COMP1RowCount
COMP1Duns = Range("A" & COMP1TotalRows).Value
COMP1Lat = Range("H" & COMP1TotalRows).Value
COMP1Long = Range("I" & COMP1TotalRows).Value
Worksheets("COMP2 Only").Activate
Range("H2:H" & COMP2RowCount).Select
Selection.FormulaR1C1 = COMP1Lat
Range("I2:I" & COMP2RowCount).Select
Selection.FormulaR1C1 = COMP1Long
For COMP2TotalRows = 2 To COMP2RowCount
If Range("L" & COMP2RowCount).Value = "CLOSEST" Then
Range("K" & COMP2RowCount).Value = COMP1Duns
Range("M" & COMP2RowCount).Value = Range("J" & COMP2RowCount).Value
Next COMP2TotalRows
Next COMP1TotalRows
End Sub
For COMP2TotalRows = 2 To COMP2RowCount
If Range("L" & COMP2RowCount).Value = "CLOSEST" Then
Range("K" & COMP2RowCount).Value = COMP1Duns
Range("M" & COMP2RowCount).Value = Range("J" & COMP2RowCount).Value
Next COMP2TotalRows
The total Macro is here:
Sub DistanceCalculation()
Dim COMP1StartingPlace, COMP1Duns, COMP1Lat, COMP1Long As String
Dim COMP2RowCount, COMP1RowCount, COMP1TotalRows, COMP2TotalRows As Integer
Worksheets("COMP2 Only").Activate
COMP2RowCount = Range("A65536").End(xlUp).Row
Worksheets("Comp1 Only").Activate
COMP1RowCount = Range("A65536").End(xlUp).Row
For COMP1TotalRows = 2 To COMP1RowCount
COMP1Duns = Range("A" & COMP1TotalRows).Value
COMP1Lat = Range("H" & COMP1TotalRows).Value
COMP1Long = Range("I" & COMP1TotalRows).Value
Worksheets("COMP2 Only").Activate
Range("H2:H" & COMP2RowCount).Select
Selection.FormulaR1C1 = COMP1Lat
Range("I2:I" & COMP2RowCount).Select
Selection.FormulaR1C1 = COMP1Long
For COMP2TotalRows = 2 To COMP2RowCount
If Range("L" & COMP2RowCount).Value = "CLOSEST" Then
Range("K" & COMP2RowCount).Value = COMP1Duns
Range("M" & COMP2RowCount).Value = Range("J" & COMP2RowCount).Value
Next COMP2TotalRows
Next COMP1TotalRows
End Sub