VBA sheet.cells(string) - 如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17838652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA sheet.cells(string) - HOW?
提问by Trenera
I want to put the cell's address/name as string rather than column, row.
我想将单元格的地址/名称作为字符串而不是列、行。
ws - a worksheet
ows - another worksheet
cell is a string = "G5"
i and c are respectivly row and columns
cell = ws.Cells(i, 1)
ows.Cells(cell).Value = ws.Cells(i, c)
___________|||||||___________
__ ___ ___ ___||||||| __ ___ ___ __
That code brings out an error.
Cheers, Vihar
该代码会出现错误。
干杯,维哈尔
回答by Paul Renton
Set ws = ThisWorkbook.Sheets("Sheet1") 'Replace with your sheet name
Set ows = ThisWorkbook.Sheets("Sheet2") 'Replace with your sheet name
cell = ws.Cells(i, 1)
ows.Range(cell).Value = ws.Cells(i, c)
Range expects a string, such as "A5" or "A5:B5", where as Cells expects two numbers separated by a comma
Range 需要一个字符串,例如“A5”或“A5:B5”,而 Cells 需要两个数字,用逗号分隔
'Examples
Cells(1,2)
Range("A5")
Range("A5:B5")
Range(Cells(10,4), Cells(8,3)) 'Use Cells as args for a Range
One other difference is Cells will return either one cell or all cells of a worksheet.
另一个区别是 Cells 将返回工作表的一个单元格或所有单元格。