我想运行一个宏,打开一个要求数组的对话框。一旦用户选择了一个单元格数组,宏就会复制这些单元格,并将它们转换为另一个工作表,从用户选择的特定单元格开始。
这是我迄今为止在本网站上发布的其他代码所汇总的内容。我对VBA的经验很少,我只是开始尝试节省分析数据的时间。
提前感谢任何可以提供帮助的人。
Sub CopyPaste()
Dim Rng As Range
Dim WorkRng As Range
Dim Arr As Variant
Dim i As Integer, j As Integer, k As Integer
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Arr = WorkRng.Formula
WorkRng.Formula = Arr
Worksheets("Sheet1").Range("Arr").Cut
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
End Sub
答案 0 :(得分:1)
这将允许用户在运行时选择复制范围和目标范围:
Sub KopyKat()
Dim r1 As Range, r2 As Range
Set r1 = Application.InputBox(Prompt:="Please select source range", Type:=8)
Sheets("Sheet2").Select
Set r2 = Application.InputBox(Prompt:="Please select destination cell", Type:=8)
r1.Copy
r2.PasteSpecial Transpose:=True
End Sub