使用VBA的Excel中的Concat并将其输出到string

我有一个要求,我试图连接从单元格A1到M1的值。 床单是dynamic的。

我想连接从单元格A1到M1的值使用VBA的string。

这个怎么做 ? 这些图纸是dynamic的,所以当我们select范围时,我希望在代码中提到图纸。

这是如何生成一个macros,如果我做单元格上的concat N1,

ActiveCell.FormulaR1C1 = "=CONCAT(RC[-13]:RC[-1])" 

谢谢。 请分享你的想法。

像这样的东西

 Sub Demo() Dim ws As Worksheet Dim cel As Range Dim str As String Set ws = ThisWorkbook.Sheets("Sheet4") 'change Sheet4 to your data sheet For Each cel In Range(ws.Range("A1"), ws.Range("M1")) str = str & cel.Value Next cel Debug.Print str End Sub 

如果您只是想将表格名称添加到公式中,但我不明白为什么。

 With ActiveCell .FormulaR1C1 = "=CONCAT(" & .Parent.Name & "!RC[-13]:RC[-1])" End With