我希望用户选择范围的子集并使用宏来选择更大的范围到剪贴板以便复制到不同的工作簿。
用户输入:
Range("A1:A5")
复制范围:
Range("A1:DM5")
现在怎么样:
用户输入:
Range("A1:C5")
复制范围:
Range("A1:DM5")
提前感谢您的任何建议。 klaus2
答案 0 :(得分:1)
Dim rng As Range
Set rng = Application.Intersect(Selection.EntireRow, Range("A:DM"))
If Not rng Is Nothing Then
rng.Copy
'etc etc
End If
答案 1 :(得分:0)
对不起,我已经好几天了。 我想出了一个似乎能给我想要的解决方案。我通过谷歌搜索找到了关键。
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