使用用户输入的范围选择语法

时间:2017-04-08 04:45:54

标签: vba excel-vba range user-input excel

这是我的代码。我正在尝试从不同的工作表中复制两个原始数据并将其粘贴到另一个工作表中。用户通过输入想要图形的原始数量来进行选择。非常感谢任何帮助。

 - 

Private Sub CommandButton1_Click() 
Dim Date1 As Variant 
Date1 = InputBox("Cell number you want to graph.  Enter any cell number from
       4 to 863", "Cell Number")

   Sheets("Deflection").Select
       *******Range("E  & "Date1":DG & "Date1" ").Select*******
       Selection.Copy
       Sheets("Static Rate Curve").Select
       Range("A2").Select
       Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
           False, Transpose:=True
       Sheets("Load").Select
       **Range("E  & "Date1":DG & "Date1" ").Select**
       Selection.Copy
       Sheets("Static Rate Curve").Select
       Range("B2").Select`enter code here`
       Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
           False, Transpose:=True
       Range("D8").Select

1 个答案:

答案 0 :(得分:0)

你需要的就是这个。

Private Sub CommandButton1_Click()
Dim wsSource1 As Worksheet, wsSource2 As Worksheet, wsDest As Worksheet
Dim Date1 As Variant

Set wsSource1 = Sheets("Deflection")
Set wsSource2 = Sheets("Load")
Set wsDest = Sheets("Static Rate Curve")

Date1 = InputBox("Cell number you want to graph. Enter any cell number from 4 to 863", "Cell Number")

wsSource1.Range("E" & Date1 & ":DG" & Date1).Copy
wsDest.Range("A2").PasteSpecial xlPasteAll, Transpose:=True

wsSource2.Range("E" & Date1 & ":DG" & Date1).Copy
wsDest.Range("B2").PasteSpecial xlPasteAll, Transpose:=True

End Sub