Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用输入框选择范围,将范围复制到另一个工作表_Vba_Variables_Range_Copy Paste_Inputbox - Fatal编程技术网

Vba 使用输入框选择范围,将范围复制到另一个工作表

Vba 使用输入框选择范围,将范围复制到另一个工作表,vba,variables,range,copy-paste,inputbox,Vba,Variables,Range,Copy Paste,Inputbox,我正在编写一个VBA宏,其中出现了一个输入框,用户将选择一个完整列的范围,然后宏将该范围粘贴到另一个工作表的特定位置。我一直在努力使这段代码正常工作,但根据我试图修复的内容,我不断收到不同的错误,所以我想知道是否有人可以帮助我。我已经粘贴了代码的相关部分: Sub Create_CONV_Files() Dim NewCode As Range Set NewCode = Application.InputBox(Prompt:="Select the column with the code

我正在编写一个VBA宏,其中出现了一个输入框,用户将选择一个完整列的范围,然后宏将该范围粘贴到另一个工作表的特定位置。我一直在努力使这段代码正常工作,但根据我试图修复的内容,我不断收到不同的错误,所以我想知道是否有人可以帮助我。我已经粘贴了代码的相关部分:

Sub Create_CONV_Files()

Dim NewCode As Range
Set NewCode = Application.InputBox(Prompt:="Select the column with the code numbers", Title:="New Event Selector", Type:=8)

Dim RawData As Worksheet
Set RawData = ActiveSheet

Dim OffSht As Worksheet
Set OffSht = Sheets.Add(After:=Sheets(Sheets.Count))
OffSht.Name = "offset.sac"

Worksheets(RawData).Range(NewCode).Copy _
  Destination:=OffSht.Range("A:A")

End Sub
我尝试过将输入改为字符串,但也出现了错误,不确定如何修复。我希望大致使用我概述的方法,因为我的完整代码有多个目标表和范围


非常感谢您提供的任何帮助

一旦设置了一个
范围
对象,它就会带来它的工作表属性,因此不需要限定它的工作表

Sub Create_CONV_Files()

    Dim NewCode As Range
    Set NewCode = Application.InputBox(prompt:="Select the column with the code numbers", title:="New Event Selector", Type:=8)

    Dim OffSht As Worksheet
    Set OffSht = Sheets.Add(After:=Sheets(Sheets.count))
    OffSht.Name = "offset.sac"

    NewCode.Copy _
    Destination:=OffSht.Range("A1")

End Sub

你真是个天才!那很有效!非常感谢你!!我能问一下你是如何把我的射程从A:A改为A1的吗?我更改了我的范围以匹配您的范围,但我想知道这是否是最佳实践类型的更改,或者目标范围是否只占用范围的第一个单元格。