Home » excel » excel – Invalid property assignment?

excel – Invalid property assignment?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I use the following macro, to massage data before it imports into our database. The criteria are, that there can be nothing in column 76 or 77, and column 82 must contain the number “99”. If all of these criteria are met, then column 6, needs to say, “Returned”. I am getting the wrong number of arguments or invalid property assignment error.

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
How to&Answers:

mySheet.Cells(i, 76, 77).Value is not a valid statment.

You need to separate it into 2 if statements

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