Sub test()
Dim temp_area As Double
Dim temp_di_lei As String
temp_area = 0
temp_di_lei = ""
i = 1
Do While Cells(i, 3).Value <> ""
If Cells(i, 3).Value <> Cells(i + 1, 3).Value And temp_area = 0 Then '说明只有一个小班
Cells(i, 7).Value = Cells(i, 2).Value
End If
If Cells(i, 3).Value = Cells(i + 1, 3).Value Then '说明是相同小班
If Cells(i, 6).Value < Cells(i + 1, 6).Value And Cells(i + 1, 6).Value > temp_area Then
temp_area = Cells(i + 1, 6).Value
temp_di_lei = Cells(i + 1, 2).Value
End If
If Cells(i, 6).Value > Cells(i + 1, 6).Value And Cells(i, 6).Value > temp_area Then
temp_area = Cells(i, 6).Value
temp_di_lei = Cells(i, 2).Value
End If
End If
If Cells(i, 3).Value <> Cells(i + 1, 3).Value And temp_area <> 0 Then '说明当前这一行小班号和下一行小班号不一样(相同小班结束)
Cells(i, 7).Value = temp_di_lei '输出最大的数据.
temp_area = 0
temp_di_lei = ""
End If
i = i + 1
Loop
End Sub
两个合并后的库,将面积最大的国土地类显示出来
最新推荐文章于 2025-06-16 15:32:41 发布
本文介绍了一段VBA代码,用于处理Excel表格中的小班数据。通过比较相邻行的小班号和面积值,找出每个小班的最大面积,并将对应类别输出到指定列。适用于土地资源管理等场景的数据分析。
9189

被折叠的 条评论
为什么被折叠?



