我希望从数千行的数组中检索前20个值。但是,工作表函数large检索的是double而不是decimal,换句话说,搜索项目将以2.1110000返回,即使该值应为0.0021110000。这是一个很大的问题,因为当我搜索时,我找不到值。
理想情况下,代码将识别数组中的前20个值,并从与前20个值相同的行号中的列中检索一些值。
Sub top20()
Dim c
bk.Range("A18") = "Top20": bk.Range("A19") = "CNumber": bk.Range("B19") = "IT": bk.Range("C19") = "SN": bk.Range("D19") = "C": bk.Range("E19") = "P"
For i = 1 To 20
fltArr = wrk.Range("AL2:AL" & wrk.Range("A1").End(xlDown).Row)
With wrk.Range("AL:AL")
searchitem = (WorksheetFunction.Large(Arg1:=fltArr, Arg2:=i))
Set c = .Find(searchitem)
If Not c Is Nothing Then
bk.Range("A20").Offset(i, 0) = wrk.Range("B" & c.Row)
bk.Range("A20").Offset(i, 1) = wrk.Range("F" & c.Row)
bk.Range("A20").Offset(i, 2) = wrk.Range("G" & c.Row)
bk.Range("A20").Offset(i, 3) = wrk.Range("H" & c.Row)
bk.Range("A20").Offset(i, 4) = wrk.Range("J" & c.Row)
End If
End With
Next i
bk.Range("A16") = "Top20p": bk.Range("A27") = "CN": bk.Range("B27") = "IT": bk.Range("C27") = "SN": bk.Range("D27") = "C": bk.Range("E27") = "P"
For i = 1 To 20
With wrk.Range("AM:AM")
Set c = .Find(WorksheetFunction.Sum(WorksheetFunction.Large(bk.Range("AL:AL"), (i))))
If Not c Is Nothing Then
bk.Range("A27").Offset(i, 0) = wrk.Range("B" & c.Row)
bk.Range("A27").Offset(i, 1) = wrk.Range("F" & c.Row)
bk.Range("A27").Offset(i, 2) = wrk.Range("G" & c.Row)
bk.Range("A27").Offset(i, 3) = wrk.Range("H" & c.Row)
bk.Range("A27").Offset(i, 4) = wrk.Range("J" & c.Row)
End If
End With
Next i
End Sub