我想把单元格的地址/名称作为字符串,而不是列、行。
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)
该代码导致一个错误。
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需要一个字符串,如"A5"或"A5:B5",其中"单元格"需要用逗号分隔的两个数字
'Examples
Cells(1,2)
Range("A5")
Range("A5:B5")
Range(Cells(10,4), Cells(8,3)) 'Use Cells as args for a Range
另一个区别是"单元格"将返回工作表的一个单元格或所有单元格。