簡體   English   中英

Excel VBA代碼將基於單元格引用的數據復制到另一個工作表

[英]Excel VBA Code to Copy Data based on a cell reference to another sheet

我想將數據從一張紙復制到Excel中的另一張紙。 數據在第一個工作表中的位置是靜態的,而要在其中復制數據的工作表,列和行是可變的,並且基於單元格數據。 我想對VB代碼有所幫助。 請考慮以下Excel表示例數據:

`Sheet1`
'A1 = Apples'
'B1 = Sheet2'
'C1 = 5'
'D1 = 10'

在上面的示例中,我想在Sheet2的第5列(也可以是E列)的第10行上將VB代碼放在“ Apples”上。單擊按鈕,將其復制過來。 提前非常感謝您在此問題上的幫助。 蘭迪

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM