简体   繁体   English

可以将工作表中两个单元格之间的范围与另一工作表中两个单元格的地址进行分类

[英]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.

相关问题 Excel将一张纸中的两个单元格与另一张纸中的两个单元格进行比较,如果它们相等,则复制一定范围的单元格 - Excel Compare two cells in one sheet to two in another, copy a certain range of cells if they are equal 将单元格范围从一张纸复制到另一张纸 - Copy range of cells from one sheet to another 将单元格范围复制到另一张纸上 - Copying range of cells to another sheet 将单元格范围插入另一张工作表 - Insert range of cells to another sheet 将数据从一张工作表上的两个单元格传输到同一 Excel 工作簿中不同工作表上的两个单元格 - Transfer data from two cells on one sheet to two cells on a different sheet in the same Excel workbook 如果第三个单元格数据变量与第一个工作表变量匹配,Excel会将两个数据单元格从一个工作表复制到另一工作表 - Excel copy two cells of data from one sheet to another sheet if a third cell data variable matches the first sheet variable 从工作表1复制到工作表4中不同单元格的单元格范围 - Range of Cells from sheet 1 copied to sheet 4 in different cells 填充Excel表格中同一列中两个相等单元格之间的所有空单元格(相等单元格的值相同) - Filling all the empty cells between two equal cells in same column in excel sheet (with the same value of the equal cells ) Sheet.Range.Value 和 Sheet.Range.Cells 之间的区别 - Difference between Sheet.Range.Value and Sheet.Range.Cells 将可变范围的单元格从一张复制到另一张 - copying variable range of cells from one sheet to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM