根据范围复制列

时间:2014-06-10 03:36:28

标签: vba

函数查明范围中的单元格是否为数字,并从另一个工作表复制所选范围 但我无法理解这一点。

Sub paste()  
    Application.ScreenUpdating = False
    Dim c As Range
    Dim lt As String
    Dim sn As String
    sn = ActiveSheet.Name

    For Each c In Range("a6:ck6")
        If c.Value.IsNumber() Then
            Sheets("1").Select
            Range("D8:D69").Select
            Selection.Copy
            Sheets(sn).Select
            MsgBox Split(ActiveCell.Address, "$")(1) = lt
            Cells(8, lt).Paste
        Else
        End If
    Next c
    Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

Dim c As Range, col As String
With Sheets(sn) '~~> Explicitly provide the sheet name here
    For Each c In .Range("A6:CK6")
        If Not IsNumeric(c.Value) Then
            col = Split(c.address, "$")(1)
            Sheets("1").Range(col & "8:" & col & "69").Copy c.Offset(2,0)
        End If
    Next
End With

以上代码检查A6:CK6是否为非数字值 如果是这样,它将复制名为" 1"的工作表上的值。在第8行到第69行的同一列上。
这是你正在尝试的吗?