类型不匹配,不知道为什么

时间:2017-12-12 02:12:55

标签: excel vba excel-vba

最近我的宏还没有解决,它在这一行上不断出现错误错误 ' v = v +表格("成员墨水#34;)。细胞(i,6)*表格("成员墨水")。细胞(i,7)&#39 ;

并且我无法弄清楚为什么,它曾经工作但最近它一直有这个错误,如果我的细胞(i,6)和细胞(i,7)都是数字,为什么它仍然有错误吗?

Sub Macro2()
'
' Macro2 Macro

Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Members Cash"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Members inkind"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Bailment"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Projects Cash"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Projects Inkind"
Sheet1.Select
Range("A1:M1").Copy
Sheets("Members Cash").Select
Range("A1:M1").PasteSpecial Paste:=xlValues
Columns("A:N").EntireColumn.AutoFit
Sheets("Members inkind").Select
Range("A1:M1").PasteSpecial Paste:=xlValues
Columns("A:N").EntireColumn.AutoFit
Sheets("Bailment").Select
Range("A1:M1").PasteSpecial Paste:=xlValues
Columns("A:N").EntireColumn.AutoFit
Range("A1:M1").Copy
Sheets("Projects Cash").Select
Range("A1:M1").PasteSpecial Paste:=xlValues
Range("A1:M1").Copy
Sheets("Projects Inkind").Select
Range("A1:M1").PasteSpecial Paste:=xlValues
With Sheet1
    .AutoFilterMode = False
    .Select
    Range("$A$1:$M$999").AutoFilter Field:=2, Criteria1:=Array("*discussion*"), Operator:=xlFilterValues
    Range(Cells(2, 2), Cells(2, 2).End(xlDown)).EntireRow.Delete
    .AutoFilterMode = False
End With
    Sheet1.AutoFilterMode = False
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=9, Criteria1:="FY17"
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=2, Criteria1:=Array("*Membership*"), Operator:=xlFilterValues
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=4, Criteria1:=("<>"), Operator:=xlAnd, Criteria2:=("<>0")


    Sheet1.Select
    Range(Cells(1, 1), Cells(1, 1).End(xlToRight).End(xlDown)).Copy
    Sheets("Cash donations").Select
    Range("A2").PasteSpecial Paste:=xlValues
    Range("A2").EntireRow.Delete

    Sheet1.AutoFilterMode = False
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=9, Criteria1:="FY17"
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=2, Criteria1:=Array("*Membership*"), Operator:=xlFilterValues
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=5, Criteria1:=("<>"), Operator:=xlAnd, Criteria2:=("<>0")

    Sheet1.Select
    Range(Cells(1, 1), Cells(1, 1).End(xlToRight).End(xlDown)).Copy
    Sheets("Members inkind").Select
    Range("A2").PasteSpecial Paste:=xlValues
    Range("A2").EntireRow.Delete

        Sheet1.AutoFilterMode = False
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=9, Criteria1:="FY17"
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=2, Criteria1:=Array("*Bailment*"), Operator:=xlFilterValues
    Sheet1.Range("$A$1:$M$999").AutoFilter Field:=5, Criteria1:=("<>"), Operator:=xlAnd, Criteria2:=("<>0")

    Sheet1.Select
    Range(Cells(1, 1), Cells(1, 1).End(xlToRight).End(xlDown)).Copy
    Sheets("Bailment").Select
    Range("A2").PasteSpecial Paste:=xlValues
    Range("A2").EntireRow.Delete

    Sheets("Members cash").Cells(1, 4).End(xlDown).Offset(1, 0) = Application.WorksheetFunction.Sum(Sheets("Members Cash").Range("D2:D999"))
    Sheets("Bailment").Cells(1, 5).End(xlDown).Offset(1, 0) = Application.WorksheetFunction.Sum(Sheets("Bailment").Range("E2:E999"))
    v = 0
    Row = Sheets("Members inkind").Cells(1, 1).End(xlDown).Row

    For i = 2 To Row

        If IsEmpty(Sheets("members inkind").Cells(i, 7)) = True Then
        v = v + Sheets("members inkind").Cells(i, 5)
        Else
        v = v + Sheets("members inkind").Cells(i, 6) * Sheets("members inkind").Cells(i, 7)
        End If

    Next i

 Sheets("Members inkind").Cells(1, 5).End(xlDown).Offset(1, 0) = v

end sub

谢谢!

1 个答案:

答案 0 :(得分:0)

您可能需要考虑尝试

v = v + Sheets("members inkind").Cells(i, 6).Value * Sheets("members inkind").Cells(i, 7).Value