嗨我正在編寫一個基於標準的數據求和代碼。下面的代碼工作完美,但它不會返回值。該代碼適用於像這樣的(= SUMIF($B$1:$DC$1,p,B2:DD2)
的Excel。原因是標準P
需要雙quotation.how到雙引號添加到P
任何建議,將不勝感激VBA:Sumif函數不能正常工作
Sub ashok()
Dim LR As Long
Dim Rg, Rg1 As Range
ActiveSheet.Range("a1").Select
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.NumberFormat = "0"
ActiveSheet.Range("a1").Select
Set Rg = Range("b1", ActiveSheet.Range("A1").End(xlToRight))
Set Rg1 = Range("b2", ActiveSheet.Range("A2").End(xlToRight))
Range("a1").End(xlToRight).Select
With ActiveCell.Offset(1, 1).Resize(LR)
.Formula = "= SumIf(" & Rg.Address(True, True) & "," & "P" & "," & Rg1.Address(False, False) & ")"
End With
End Sub
[在VBA放置在雙引號內的String]的可能的複製(https://stackoverflow.com/questions/42960548 /放置雙引號內的字符串在VBA) –