Public Sub sum100do()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do While i <= 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doUT()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do Until i > 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doLW()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop While i <= 100
MsgBox sum1
End Sub
Public Sub sum100doLU()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop Until i > 100
MsgBox sum1
End Sub
你用的sumif公式,第2个参数想输入数组,对吧?在excel表格中,如果这样输入,要是要按ctrl+shift+enter告诉excel你要玩数组。
可是在VBA中,还支持数组公式吗?既然你这试验失败,证明vba中调用公式不支持数组公式了。
既然用到VBA了,还怕它不成?
FOR I = LBOUND(ARR) TO UBOUND(ARR)
QQ=QQ+APPLICATIONSUMIF(RANGE("A:A"),ARR(I),RANGE("B:B"))
NEXT I
CELLS(13,1)=QQ
'定义一个宏就行了
Sub mysum()
Dim i As Integer, r As Integer, c As Integer
Dim size As Variant
size = Array(4, 3, 3)
With ActiveSheet
r = UsedRangeRow
c = UsedRangeColumn
For i = LBound(size) To UBound(size)
Cells(r, c + 2)Resize(size(i))Value = WorksheetFunctionsum(Cells(r, c)Resize(size(i)))
r = r + size(i)
Next i
End With
End Sub
你没有要求输入输出位置
以下代码可以达到你的要求
有其他要求就自己改代码吧
Sub 数字串求和()Dim a
a = InputBox("请输入数字", 1)
Dim n
n = Len(a)
Dim x As Integer
For i = 1 To n
x = x + Mid(a, i, 1)
Next
MsgBox "数字串之和为:" & x
End Sub
已上传附件
如果你是在 Excel VBA 中写代码,那可以充分利用 Excel 内置的函数 (SUM 和 ROW),所以这里可以不用循环,一行关键代码即可搞定!
MsgBox ApplicationEvaluate("=SUM(ROW(1:100))")对应到你的代码中,只需将 100 替换成 n 即可,也就是:
MsgBox ApplicationEvaluate("=SUM(ROW(1:" & n & "))")希望能够帮到你。
hi,本来想把改动的地方标出来,后来发现改动还蛮多的,就不一一标出了,现在应该可以运行了。
Sub Test()
Dim i As Integer, iRow As Integer
Dim strPath As String
Dim TheSheet As Worksheet
iRow = 1
Set TheSheet = ActiveWorkbookWorksheets("sheet1")
strPath = ""E:\可丢\hua"
With ApplicationFileSearch
LookIn = strPath
SearchSubFolders = True
Filename = ""
If Execute > 0 Then
For i = 1 To FoundFilesCount
'Range("A" & i) = FoundFiles(i)
WorkbooksOpen (FoundFiles(i))
For j = 1 To ActiveWorkbookWorksheetsCount
'ActiveWorkbookWorksheets(i)Cells(1, 1)Value = "a"
ActiveWorkbookWorksheets(j)UsedRangeCopy
TheSheetActivate
While TheSheetRange("a" & iRow)Value <> ""
iRow = iRow + 1
Wend
TheSheetRange("A" & iRow)Select
ActiveSheetPaste
ActiveWorkbookSave
Next j
Workbooks(WorkbooksCount)Close
Next i
End If
End With
End Sub
以上就是关于求救:用规定的vba语言求和(1——100)全部的内容,包括:求救:用规定的vba语言求和(1——100)、VBA自定义数组求和,求A列含字母b、c,对应B列数字求和代码、Excel vba累加求和等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)