2014-10-01 38 views
-2

我想讓用戶選擇一個範圍的子集並使用宏選擇剪切板的更大範圍以複製到不同的工作簿。Excel:用戶選擇到更大範圍的副本

用戶輸入: Range("A1:A5") 複製的範圍: Range("A1:DM5")

現在怎麼樣: 用戶輸入: Range("A1:C5") 複製的範圍: Range("A1:DM5")

感謝提前任何建議。 klaus2

+0

如何確定較大的範圍內? – Degustaf 2014-10-01 22:23:46

+0

它將始終是Ax:DMx。 我想如果我可以確定哪一行被選中,那麼我可以定義複製的範圍。 – klaus2 2014-10-01 23:29:36

回答

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 
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 

末次

+0

謝謝你的建議蒂姆。我還沒有嘗試過,但會。 – klaus2 2014-10-06 22:19:18