level 3
Sub CalculateMinEnclosingCircle()
Dim ws As Worksheet
Dim lastRow As Long
Dim totalDiameter As Double
Dim i As Long
Set ws = ThisWorkbook.ActiveSheet iveSheet,%E7%BD%91%E9%A1%B5%E9%93%BE%E6%8E%A5) lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
totalDiameter = 0
For i = 2 To lastRow
If IsNumeric(ws.Cells(i, 1).Value) And IsNumeric(ws.Cells(i, 2).Value) Then
' 累加所有圆的直径(直径 × 数量)
totalDiameter = totalDiameter + (ws.Cells(i, 1).Value * ws.Cells(i, 2).Value)
Else
MsgBox "第 " & i & " 行数据格式错误,请检查!"
Exit Sub
End If
Next i
' 输出结果(假设排列为直线,外切圆直径为总长度)
ws.Range("C2").Value = totalDiameter
MsgBox "最小外切圆直径为:" & totalDiameter
End Sub
2025年05月12日 10点05分
