简体   繁体   English

Excel VBA代码将基于单元格引用的数据复制到另一个工作表

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

相关问题 Excel 使用 VBA 将单元格数据从一张纸复制到另一张纸 - Excel Copy Cell Data from one sheet to another using VBA Excel宏和VBA,将单元格范围复制到另一个工作表(转置并基于另一个值) - Excel Macro & VBA, Copy Cell Range to another sheet (transposed and based on another value) Excel VBA 根据第二列单元格值将列从一张表复制到另一张表 - Excel VBA to Copy Column from one sheet to another based on a second columns cell value 根据列表复制工作表和单元格值,并使用 excel vba 代码根据列表重命名 - copy sheet and cell value based on list and rename as per list with excel vba code Excel VBA根据单元格数据将整个行复制到新工作表 - Excel VBA copy entire row to new sheet based off cell data Excel VBA将单元格复制到另一个工作表,同时保持超链接 - Excel VBA Copy Cell to another sheet while keeping Hyperlink 如果单元格值大于0,excel vba将单元格复制到另一个工作表 - excel vba copy cells to another sheet if cell value is greater than 0 Excel VBA将特定的单元格复制并粘贴到另一个工作表 - Excel VBA copy and paste a specific cell to another Sheet 如何从Module-Excel VBA中的另一个工作表引用单元格? - How to reference cell from another sheet in Module - Excel VBA? Excel VBA代码(分配给按钮)可基于另一个工作表中的单元格值隐藏/取消隐藏行 - Excel VBA code (assigned to a button) to hide/unhide rows based on cell values across another sheet
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM