我無法評估代碼最後的產品。我覺得所有東西都正常,但我不斷收到評估產品
類型不匹配錯誤
我已經試過各種語法的變化,我仍然不能得到它的工作。有任何想法嗎?
Sub Sample()
Dim ws As Worksheet
Dim x As Long
Dim lRow As Long, llRow As Long
Dim aCell As Range, bCell As Range
Dim rng1 As Range, rng2 As Range
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
Set aCell = .Range("B6:E20").Find(Cells(14, 9).Offset(0, -1).Value)
If Not aCell Is Nothing Then
lRow = .Range(Split(.Cells(, aCell.Column).Address, "$")(1) & .Rows.Count).End(xlUp).Row
If lRow > 1 Then
Set rng1 = .Range(aCell.Offset(1), .Cells(lRow, aCell.Column))
End If
End If
Set bCell = .Range("B6:E20").Find(Cells(14, 9).Offset(-1, 0).Value)
If Not bCell Is Nothing Then
llRow = .Range(Split(.Cells(, bCell.Column).Address, "$")(1) & .Rows.Count).End(xlUp).Row
If llRow > 1 Then
Set rng2 = .Range(bCell.Offset(1), .Cells(lRow, bCell.Column))
End If
End If
Debug.Print rng1.Address
Debug.Print rng2.Address
x = Evaluate("=sumproduct(""rng1"",""rng2"")")
End With
End Sub
目前尚不清楚你正在努力完成什麼。 'set rng2 = ...'應該使用'llrow'而不是'lrow',我相信它應該是'... Find(.Cells(14,9)...'not'... Find(Cells( 14,9)...'同樣,fwiw,單元格在[SUMPRODUCT函數]範圍內(https://support.office.com/zh-cn/article/sumproduct-function-4e0bffa7-4291-4635-a61f所有的行都應該有相同的行數 – Jeeped