我需要从sheet1
的一系列单元格中复制内容,例如A1:A10
,并将所有数据粘贴到sheet2
中单个单元格A1
中。
这似乎是一个简单的使用案例,但我迄今为止找不到任何解决方案。以下是我尝试过的方法:
' Attempt 1
Sheets("shee1").Select
Range("A1:A10").Select
Selection.Copy
MsgBox Selection.Text ' Error: Type mismatch. If I add Selection.Text to watch I see an array kind of structure with each index having each cell data
Dim val = Selection.Text
Sheets("sheet2").Select
Range("A1") = val
' Attempt 2
Sheets("sheet1").Range("A1:A10").Copy(Sheets("sheet2").Range("A1") 'Doesn't copy in single cell A1, instead copies to multiple rows like in source
CONCATENATE
或TEXTJOIN
函数。 - BigBenARRAYTOTEXT(A1:A10)
(自MS 365版本起可用) - T.M.