Excel VBA Coincatenate Cells包含 – &:

我正在修改一些代码,在汇总表和成本计算表之间添加链接。 我试图编写以下公式到单元格C1中的每个CS工作表。 = CONCATENATE(SUMMARY!L9,“ – ”,SUMMARY!M9,“:”,SUMMARY!N9),其中行将改变。 我在语法上遇到了麻烦。 什么是最简单的方法来实现呢?

下面的代码(这几乎可以工作,但没有把所需的“纳入公式

Sub CSrefs() ' ' Adds links from Summary Sheet to CS Sheets: - Updated 29/09/15 PRS Dim i As Integer, iOffset As Integer, intCount As Integer Dim intCS1_Index As Integer, intCSCount As Integer, nonCSSheets As Integer Dim sFormulaText As String, sDash As String, sDots As String Application.ScreenUpdating = False intCount = ActiveWorkbook.Sheets.Count 'Find total number of workbook sheets intCS1_Index = Sheets("CS1").Index 'CS1 Sheet index intCSCount = intCount - (intCS1_Index - 1) 'Find total number of CS sheets nonCSSheets = intCount - intCSCount 'Find total number of Non-CS sheets sDash = " - " sDots = " : " For i = 1 To intCSCount 'number of sheets iOffset = i + 8 'Start of Summary Sheet CS Rows With Sheets("CS" & i) sFormulaText = "=CONCATENATE(SUMMARY!L" & iOffset & "," & sDash & ",SUMMARY!M" & iOffset & "," & sDots & ",SUMMARY!N" & iOffset & ")" ' .Range("B1").Formula = sFormulaText .Range("A1").Hyperlinks.Add Anchor:=.Range("A1"), Address:="", SubAddress:="Summary!D" & iOffset, TextToDisplay:="SUMMARY" 'Go to Summary Sheet hyperlink .Range("A1").Font.Size = 8 .Range("G1").Formula = "=SUMMARY!O" & iOffset ' UOM .Range("E1").Formula = "=SUMMARY!P" & iOffset 'SOR Qty .Range("I1").Formula = "=SUMMARY!R" & iOffset 'Cable Average ' .Range("H10").Formula = "=SUMMARY!C" & iOffset 'Sage Code .Range("N17").Formula = "=SUMMARY!AC" & iOffset 'Materials GP% .Range("P17").Formula = "=SUMMARY!AP" & iOffset 'Materials MCD GP% .Range("N42").Formula = "=SUMMARY!AD" & iOffset 'Misc GP% .Range("P42").Formula = "=SUMMARY!AP" & iOffset 'Misc MCD GP% .Range("N67").Formula = "=SUMMARY!AE" & iOffset 'Labour GP .Range("P67").Formula = "=SUMMARY!AP" & iOffset 'Labour MCD GP% .Range("N92").Formula = "=SUMMARY!AF" & iOffset '3rd Party GP% .Range("P92").Formula = "=SUMMARY!AP" & iOffset '3rd Party MCD GP% .Range("N117").Formula = "=SUMMARY!AG" & iOffset 'PM&PL GP% .Range("P117").Formula = "=SUMMARY!AP" & iOffset 'PM&PL MCD GP% .Range("N142").Formula = "=SUMMARY!AH" & iOffset 'Bond GP% .Range("P142").Formula = "=SUMMARY!AP" & iOffset 'Bond MCD GP% .Range("N152").Formula = "=SUMMARY!AG" & iOffset 'Support GP% .Range("P152").Formula = "=SUMMARY!AP" & iOffset 'Support MCD GP% .Range("N177").Formula = "=SUMMARY!AH" & iOffset 'Day Works GP% .Range("P177").Formula = "=SUMMARY!AP" & iOffset 'Day Works MCD GP% End With Next i Sheets("Summary").Select Application.ScreenUpdating = True End Sub 

在双引号内使用两个双引号使双引号出现

 sFormulaText = "=CONCATENATE(SUMMARY!L" & iOffset & ",""-"",SUMMARY!M" & iOffset & ", "":"",SUMMARY!N" & iOffset & ")" 

不知道是否你需要双引号和短划线/点之间的空间,但你可以自己添加:)