[英]How do I execute a proper IF-THEN statement?
When I run this module I get an Object Required error.当我运行此模块时,出现 Object Required 错误。 I'm a novice with VBA and I don't see what's wrong with the code.
我是 VBA 的新手,我看不出代码有什么问题。
Sub CountOccurances()
Dim Total As Integer
Dim Column As Integer
Dim Row As Integer
Total = 0
For Column = 2 To 51
If Worksheets("Sheet1").[13,Column].Value = 1 Then
For Row = 12 To 16
If Worksheets("Sheet1").[Row, Column].Value = 2 Then Worksheets("Sheet1").[20,Row+8].Value = Total + 1
Next Row
End If
Next Column
End Sub
I have tried a few modifications, but without success.我尝试了一些修改,但没有成功。
Use the Cells property, as in:使用 Cells 属性,如下所示:
Worksheets("Sheet1").Cells(13, Column).Value = 1
instead of the shortcut notation;而不是快捷符号; the latter is good for a range defined by a starting and ending cell reference separated by a colon (like [A1:C5])
后者适用于由冒号分隔的起始和结束单元格引用定义的范围(如 [A1:C5])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.