VBA:结合两个单元格形成一个系列名称

我想把两个不同的单元格中的两个文本片段组合成一个系列的名字。 两块之间应该有一个空格。 不幸的是,我得到了一个

运行时错误1004

Dim Dataws As Worksheet Dim Chtws As Worksheet Set Dataws = ThisWorkbook.Sheets("Overview") Set Chtws = ThisWorkbook.Sheets("Chart") Set ChtObj = Chtws.ChartObjects("ChartA") With Dataws CurrentRow = 13 Do Until Range("A" & CurrentRow) = "" CurrentRow = CurrentRow + 1 Loop End With With ChtObj Set Ser = .Chart.SeriesCollection.NewSeries With Ser .Name = "=" & Dataws.Cells(CurrentRow, 4).Address(False, False, xlA1, xlExternal) & " " & Dataws.Cells(CurrentRow, 1).Address(False, False, xlA1, xlExternal) .XValues = "=" & Dataws.Cells(CurrentRow, 5).Address(False, False, xlA1, xlExternal) .Values = "=" & Dataws.Cells(CurrentRow, 6).Address(False, False, xlA1, xlExternal) End With End With End Sub 

.Name = Dataws.Cells(CurrentRow, 4).Text & " " & Dataws.Cells(CurrentRow, 1).Text将是你需要的公式。

你的.Address(False, False, xlA1, xlExternal)会返回给你外部单元格引用。 当你声明你想要结合两个单元格的文本,你应该使用.Text

由于你的公式现在不计算有用的东西,你在开始时应该被删除。