[英]Cancatenate the range between two cells in a sheet from addresses of two cells in another sheet
I have two cells in sheet1 that contain address for two cells in sheet2. 我在sheet1中有两个单元格,其中包含Sheet2中两个单元格的地址。 for example in sheet1, the cells(1,1).value has the address $A$6 and cells(1,2) has the address $A$100. 例如在sheet1中,cells(1,1).value的地址为$ A $ 6,cells(1,2)的地址为$ A $ 100。 These two addresses refers to two cells in sheet2. 这两个地址引用了sheet2中的两个单元格。 Now I want to concatenate the range between $A$6 to $A$100 from sheet2. 现在,我想将sheet2中介于$ A $ 6到$ A $ 100之间的范围连接起来。
My code doesn't work: 我的代码不起作用:
Sub concatenate()
Set wss = Sheets("sheet1").Range("sheet2.Cells(1, 1).Value : sheet2.Cells(1, 2).Value")
For Each cel In wss
tval = tval & cel.Value
Next
Sheets("sheet2").Cells(1, 7).Value = tval
End Sub
Your syntax is incorrect because you're passing the whole parameter as a string, while it should be variables and strings. 您的语法不正确,因为您要将整个参数作为字符串传递,而它应该是变量和字符串。 This should work, say all the rest is good: 说其余的都很好,这应该可以工作:
Set wss = Sheets("sheet1").Range(sheet2.Cells(1, 1).Value & ":" & sheet2.Cells(1, 2).Value)
Explanation 说明
This: sheet2.Cells(1,1).Value
returns "$A$6"
if executed; 如果执行,则sheet2.Cells(1,1).Value
返回"$A$6"
; but, if you write it into a string as you did above (ie "sheet2.Cells(1,1).Value"
), it means exactly "sheet2.Cells(1,1).Value"
. 但是,如果像上面那样将其写入字符串(即"sheet2.Cells(1,1).Value"
),则其含义恰好是"sheet2.Cells(1,1).Value"
。 And clearly, the Range("sheet2.Cells(1,1).Value")
doesn't exist. 显然, Range("sheet2.Cells(1,1).Value")
不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.