2014-02-10 85 views
1

我使用下面的宏,在導入到我們的數據庫之前按摩數據。標準是,列76或77中不存在任何內容,列82必須包含數字「99」。如果滿足所有這些標準,則第6列需要說「返回」。我收到錯誤的參數數量或無效的屬性分配錯誤。無效的屬性分配?

Sub V_11() 
    Dim mySheet As Worksheet, myBook As Workbook 'Define your workbooks and worksheets as variables 
    Set myBook = Excel.ActiveWorkbook 
    Set mySheet = myBook.Sheets("Sheet1") 
    Dim i As Integer, j As Integer 'Define a couple integer variables for counting 
    j = 2 
    For i = 2 To mySheet.UsedRange.Rows.Count 
     If IsEmpty(mySheet.Cells(i, 76, 77).Value) And mySheet.Cells(i, 82) = "99" Then 
      mySheet.Cells(i, 6).Value = "Returned" ' . . . place the text "N/A" into the cell in row "j" in Sheet2. 
     End If 
    Next 
End Sub 

回答

3

mySheet.Cells(i, 76, 77).Value不是有效statment。

你需要將它分成2 if語句

If IsEmpty(mySheet.Cells(i, 76)) And IsEmpty(mySheet.Cells(i, 77)) And mySheet.Cells(i, 82) = "99" Then 
+1

1+不錯的抓:) –

+1

這完美地工作!非常感謝! – autumntiger