简体   繁体   中英

How do I execute a proper IF-THEN statement?

When I run this module I get an Object Required error. I'm a novice with VBA and I don't see what's wrong with the code.

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:

 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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM