我有两张纸(称为ONE和TWO)。我想将固定范围的单元格从ONE复制到目标中。但是TWO中的目标地址是ONE中固定单元格中的字符串值。
例如,ONE!C37的字符串值为“A1500”。我想从ONE复制单元格!A32:ONE!W32到TWO!A1500。并且,当单元格ONE C37中的字符串值发生变化时,TWO中的目标目标也会发生变化。
一定很容易,但我看不出怎么做。任何帮助将不胜感激。
答案 0 :(得分:0)
富。试一试:
Sub movetosheet2()
Dim sheet_one_rng As Range:
Dim sheet_two_rng As Range:
Dim sheet_two_address As String:
Set sheet_one_rng = Worksheets("Sheet1").Range("A1:B5")
'Set the range from sheet 1 you'd like to copy onto sheet two
sheet_two_address = Worksheets("Sheet1").Range("D1").Value
'Supposing your location of "A1500" is stored in cell D1 on Sheet1
'Note that the value of the D1 cell needs to be A1500:A1500
'and NOT just A1500
'You are essentially generating a string to pass into a range argument
'Set the destination range on Sheet 2 using your string
Set sheet_two_rng = Worksheets("Sheet2").Range(sheet_two_address)
'Use the Range.Copy method
sheet_one_rng.Copy Destination:=sheet_two_rng
End Sub
希望有所帮助!
答案 1 :(得分:0)
尝试以下代码:
Sub CopyRange()
Dim RngSource As Range
Dim RngDest As Range
Dim DestString As String
' set source range from sheet "ONE"
Set RngSource = Sheets("ONE").Range("A32:W32")
' read destination range from cell "A37" in sheet "ONE"
DestString = Sheets("ONE").Range("A37").Value
' set destination range from sheet "TWO"
Set RngDest = Sheets("TWO").Range(DestString)
' copy from Sheet "ONE" to Sheet "TWO"
RngSource.Copy Destination:=RngDest
End Sub
答案 2 :(得分:0)
你只需要一行:
Worksheets("ONE").Range("A32:W32").Copy Destination:=Worksheets("TWO").Range(Worksheets("ONE").Range("C37").Value)
或者,使用With-End With
阻止并避免重复:
With Worksheets("ONE")
.Range("A32:W32").Copy Destination:=Worksheets("TWO").Range(.Range("C37").Value)
End With