我得到了一个
400错误
单击我的宏时,当我在Visual Basic中并使用F8步进时它工作正常但是当我点击Calculate Stats宏时它会给出一个
400错误
除非我手动在其中一行中添加日期,否则不会运行它。我希望它在没有输入日期的情况下运行并自动计算日期。对不起,我是编程新手,不知道我能说些什么才有意义。请参阅以下代码:
Sub CalculateStats_Click()
Dim i As Integer
Dim x As Integer
'start row specified below as i
i = 12
'stop row specified as x
x = 94
Dim startloc As String
Dim stoploc As String
Dim reportcol As Integer
Range("A11").End(xlToLeft).Select
ActiveCell.Offset(0, 1).Select
ActiveCell = Date
reportcol = ActiveCell.Column
Do While i < x
startloc = "H" & i
stoploc = "I" & i
Cells(i, reportcol).Value = WorksheetFunction.Sum(Worksheets("Analysts").Range(Worksheets("Analysts").Range(startloc), Worksheets("Analysts").Range(stoploc)))
i = i + 1
Loop
End Sub
这是我对你要做的事情的最好猜测:
Sub CalculateStats_Click()
Const RW_START As Long = 12
Const RW_END As Long = 93
Const COL_SUM_START As Long = 8 'H
Dim i As Long, sht As Worksheet, c As Range
Set sht = Worksheets("Analysts")
'find the first empty header cell and populate the date
Set c = sht.Cells(RW_START - 1, sht.Columns.Count).End(xlToLeft).Offset(0, 1)
c.Value = Date
For i = RW_START To RW_END
sht.Cells(i, c.Column).Value = _
Application.Sum(sht.Cells(i, COL_SUM_START).Resize(1, 2))
Next
End Sub
我已经解决了这个问题。感谢您对此的帮助,但这是因为宏未分配给正确的模块。
我该如何关闭这张票?