|
本帖最后由 linbohen 于 2014-7-3 13:35 编辑
请各位看看,如何让这个函数带上如图红色框里的参数,实现任意工作表里任意列的统计。谢谢。
- Function tongji(sht1 As Worksheet, sht2 As Worksheet, col2 As Long)
- Dim Sheet1 As Worksheet, Sheet2 As Worksheet
- Dim mycol As Integer, cheng As Integer
- tongji = " "
- If col2 <= 0 Or col2 > Columns.Count Then Exit Function
-
- For mycol = 1 To 500
- If Sheet1.Cells(mycol, col2).Value <> " " Then
- cheng = sht1.Cells(mycol, col2).Value * sht1.Cells(mycol, 3).Value
- tongji = tongji & " " & sht1.Cells(mycol, 1).Value & sht1.Cells(mycol, col2).Value & "*" & sht1.Cells(mycol, 3).Value & "=" & CStr(cheng)
- End If
- Next mycol
- End Function
复制代码楼主自己测试吧。
|
|