Excel:将用户选择复制到更大范围

Excel:将用户选择复制到更大范围,excel,vba,Excel,Vba,我想让用户选择一个范围的子集,并使用宏选择更大的范围到剪贴板,以便复制到其他工作簿 用户输入: 范围(“A1:A5”) 复制范围: 范围(“A1:DM5”) 现在我们来看看: 用户输入: 范围(“A1:C5”) 复制范围: 范围(“A1:DM5”) 提前谢谢你的建议。 克劳斯2对不起,我已经好几天没来了。 我想出了一个解决办法,似乎能满足我的需求。我通过谷歌搜索找到了钥匙 Dim strSelection As String Dim firstRow As Integer Dim lastRow

我想让用户选择一个范围的子集,并使用宏选择更大的范围到剪贴板,以便复制到其他工作簿

用户输入:
范围(“A1:A5”)
复制范围:
范围(“A1:DM5”)

现在我们来看看: 用户输入:
范围(“A1:C5”)
复制范围:
范围(“A1:DM5”)

提前谢谢你的建议。
克劳斯2

对不起,我已经好几天没来了。 我想出了一个解决办法,似乎能满足我的需求。我通过谷歌搜索找到了钥匙

Dim strSelection As String
Dim firstRow As Integer
Dim lastRow As Integer
Dim firstCell As String
Dim lastCell As String

Sub Macro3()
  strSelection = Selection.Address(ReferenceStyle:=xlA1, _
                       RowAbsolute:=False, ColumnAbsolute:=False)
  firstRow = Range(strSelection).Row
  lastRow = Range(strSelection).Rows.Count + Range(strSelection).Row - 1
  firstCell = "A" & firstRow 'will always be "A" + firstRow
  lastCell = "I" & lastRow 'will always predetermined column + lastRow 
  Range(firstCell, lastCell).Select 'selects the range and ready for copying to another workbook
  MsgBox firstCell 'testing
  MsgBox lastCell 'testing

End Sub

如何确定更大的范围?它将始终是Ax:DMx。我想如果我能确定选择了哪些行,那么我就可以定义复制的范围。谢谢你的建议。我还没试过,但我会的。
Dim strSelection As String
Dim firstRow As Integer
Dim lastRow As Integer
Dim firstCell As String
Dim lastCell As String

Sub Macro3()
  strSelection = Selection.Address(ReferenceStyle:=xlA1, _
                       RowAbsolute:=False, ColumnAbsolute:=False)
  firstRow = Range(strSelection).Row
  lastRow = Range(strSelection).Rows.Count + Range(strSelection).Row - 1
  firstCell = "A" & firstRow 'will always be "A" + firstRow
  lastCell = "I" & lastRow 'will always predetermined column + lastRow 
  Range(firstCell, lastCell).Select 'selects the range and ready for copying to another workbook
  MsgBox firstCell 'testing
  MsgBox lastCell 'testing