我的问题是,不确定是否可以做到:(需要使用vba)我有一个范围,每组5年(每组一栏,2012年、2013年和2014年各一栏),这些栏目都有等级。我需要在所有的团体中找到最高的分数,但只在2013年。我知道如何找到更高的等级,但它在所有的列中搜索。我能找到这个等级,但只能在2013年的栏目中搜索吗?
发布于 2017-07-19 20:21:48
这段代码应该能帮到你。这是一个非常通用的代码,可以按照您的要求执行。您可以通过创建一个UserForm并询问用户您希望识别的列标题(而不是只查找2013年)来扩展它。
Sub
Dim lastColumn As Long
Dim max_value As Double
max_value = 0
lastColumn = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To lastColumn
' Seek out the column you desire!
If Worksheets("Sheet1").Cells(2,i).Value = "2013" Then
Dim lastRow As Long
lastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
' Go through the entire column of the desired type to read the values
For j = 3 To lastRow
If Worksheets("Sheet1").Cells(j, i).Value > max_val Then
max_value = Worksheets("Sheet1").Cells(j, i).Value
End If
Next j
End If
Next
End Subhttps://stackoverflow.com/questions/45199494
复制相似问题