[英]Excel VBA Code to Copy Data based on a cell reference to another sheet
I would like to have data from one sheet copied to another sheet in Excel. 我想将数据从一张纸复制到Excel中的另一张纸。 The location of the data in the firs sheet is static, while the Sheet, Column, and Row in which the data is being copied is variable, and based on cell data.
数据在第一个工作表中的位置是静态的,而要在其中复制数据的工作表,列和行是可变的,并且基于单元格数据。 I would like a bit of help with the VB Code.
我想对VB代码有所帮助。 Consider the following Excel Table Sample Data:
请考虑以下Excel表示例数据:
`Sheet1`
'A1 = Apples'
'B1 = Sheet2'
'C1 = 5'
'D1 = 10'
In the above sample, i would like to have a VB code place "Apples" on Sheet2 at Column 5 (can be column E as well), Row 10. On the click of a button, this will be copied over. 在上面的示例中,我想在Sheet2的第5列(也可以是E列)的第10行上将VB代码放在“ Apples”上。单击按钮,将其复制过来。 Thanks so much in advance for your help in this matter.
提前非常感谢您在此问题上的帮助。 Randy
兰迪
Dim sht, rw, col, val
With ThisWorkbook.sheets("Sheet1")
val = .Range("A1").Value
sht = .Range("B1").Value
col = .Range("C1").Value
rw = .Range("D1").Value
End with
if isnumeric(col) then
thisworkbook.sheets(sht).Cells(rw,col).value = val
else
thisworkbook.sheets(sht).Range(col & rw).value = val
end if
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.