我在下面的代码遇到问题。它工作正常,但并没有完全符合我的要求。
Sub Sum()
Dim frm As String
Dim startCell As String
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = Workbooks("EP_BB_DK_ny.xlsm")
Set wb2 = Workbooks("Låneoversigt.xlsm")
Set wb1sht = wb1.Worksheets("Facility Overview")
Set wb2sht = wb2.Worksheets("låneoversigt")
startCell = Left(wb2sht.Range("A120").Value, 8)
frm = "=SUMPRODUCT((LEFT('[" & wb1.Name & "]" & wb1sht.Name & "'!G7:G100,8)=" & startCell & ")*('[" & wb1.Name & "]" & wb1sht.Name & "'!AA7:AA100))"
With wb2sht.Range("DV2")
.Formula = frm
End With
End Sub
代码的结果是:
=SUMPRODUCT((LEFT('[EP_BB_DK_ny.xlsm]Facility Overview'!G7:G100;8)=16908636)*('[EP_BB_DK_ny.xlsm]Facility Overview'!AA7:AA100))
我需要它在值16908636上加上双等号,如下所示
=SUMPRODUCT((LEFT('[EP_BB_DK_ny.xlsm]Facility Overview'!G7:G100;8)="16908636")*('[EP_BB_DK_ny.xlsm]Facility Overview'!AA7:AA100))
我试过""" &安培; startCell& """但它没有用。
有什么想法吗?
提前致谢:)
答案 0 :(得分:0)
找到解决方案:)
=SUMPRODUCT((LEFT('[EP_BB_DK_ny.xlsm]Facility Overview'!G7:G100;8)=LEFT(16908636011;8))*('[EP_BB_DK_ny.xlsm]Facility Overview'!AA7:AA100))
答案 1 :(得分:0)
试试"""" & startCell & """" 'use four double quotes
像:
=SUMPRODUCT((LEFT('[EP_BB_DK_ny.xlsm]Facility Overview'!G7:G100;8)="""" & 16908636 & """")*('[EP_BB_DK_ny.xlsm]Facility Overview'!AA7:AA100))
或者
试试Char(34) & startCell & Char(34)
像:
=SUMPRODUCT((LEFT('[EP_BB_DK_ny.xlsm]Facility Overview'!G7:G100;8)=Char(34) & 16908636 & Char(34))*('[EP_BB_DK_ny.xlsm]Facility Overview'!AA7:AA100))
使用您认为合适的方法。
对Stackoverflow的信用。