
求EXCEL VBA 程序:在EXCEL的A1到E1里分别有数据1,3,9,4,5。在A3到E3里分别有数据7,4
Application.Volatile
Dim tmp, arr1, arr2, i, j, s
If Not IsNumeric(iRes) Then tmp = "#iRes<>number": GoTo 1000
arr1 = Rng1.Rows(1)
arr2 = Rng2.Rows(1)
If UBound(arr1, 2) <> UBound(arr2, 2) Then tmp = "#Rng1<>Rng2": GoTo 1000
……
详细Hi我,给你完整代码
Dim i, c, k, str1
Set rng = Range("a3:e3")
i = 1
Do Until k >= 20
For Each c In rng
If c = Application.WorksheetFunction.Large(rng, i) Then
k = k + c
str1 = str1 & "," & Cells(1, c.Column)
Exit For
End If
Next c
i = i + 1
If i = rng.Count Then Exit Do
Loop
Range("a5") = Mid(str1, 2, Len(str1))
MsgBox "结果已输出至A5单元格: " & Mid(str1, 2, Len(str1))
End Sub
这插入后没有自定义函数?
这不是自定义函数,是程序,必须手动执行
Sub aa()
Dim i, j, a(5), b(5), t1, t2, t3, t4
For i = 1 To 5
a(i) = Cells(3, i)
b(i) = i
Next
For i = 1 To 5
For j = i + 1 To 5
If a(i) < a(j) Then
t1 = a(j): a(j) = a(i): a(i) = t1
t2 = b(j): b(j) = b(i): b(i) = t2
End If
Next
Next
t3 = 0: t4 = ""
For i = 1 To 5
t3 = t3 + a(i)
If t4 = "" Then
t4 = cells(1,b(i))
Else
t4 = t4 & "," & cells(1,b(i))
End If
If t3 >= 20 Then Cells(5, 1) = t4: Exit For
Next
End Sub
这VBA运行时有问题?
—— 说的并不清楚,没法写代码。
调用格式类似:Call iSumLarge(25, Range("a2:j2"))
B130487,希望对你有用
这不能做成自定义函数?