简体   繁体   English

Excel vba 选择。复制

[英]Excel vba Selection.Copy

i would like to insert an if-operator, who check that the selection area is from Column A to L我想插入一个 if 运算符,检查选择区域是否从 A 列到 L

This is my code: The Probleme here is that i can select one column but they had to select column A to L这是我的代码:这里的问题是我可以 select 一列,但他们必须 select A 到 L 列

Selection.Copy Destination:=Sheets("Archiv").Range("A" & Sheets("Archiv").Range("A" & Rows.Count).End(xlUp).Row).Rows.Offset(1)
 
 Selection.Delete Shift:=xlUp

Thanks谢谢

Like this:像这样:

Sub Tester()
    Const MSG As String = "Please select a continuous range from ColA to ColM"
    
    If TypeOf Selection Is Range Then  'make sure a range is selected...
        With Selection
            If .Areas.Count = 1 Then   'must be a single area
                If .Cells(1).Column = 1 And .Columns.Count = 12 Then 'A to M
                    'good to go...
                Else
                    MsgBox MSG
                End If
            Else
                MsgBox MSG
            End If
        End With
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM