构建行的字符串,然后切割到同一工作簿中的工作表

时间:2017-12-14 21:01:44

标签: excel-vba vba excel

我正在获取Method' Range'对象' _Global'在以下代码的下面一行失败。

Dim myRange As String

    For c = 7 To ioFileLastRow Step 1
       If Left(ioFilePreEx.Cells(c, 21), 4) <> "DIVD" Then
        myRange = myRange & "," & c & ":" & c
       End If
       Next c

    Range(Left(myRange, Len(myRange) - 1)).Cut Destination:=ioFilePreEx1.Range("A" & ioFileLastRow).End(xlUp).Offset(1) 'Error Occurs Here
       End Sub

请帮忙。 谢谢!

1 个答案:

答案 0 :(得分:0)

Dim myRange As String
c = 7
Do Until ioFilePreEx.Cells(c, 1).Value = vbNullString
If ioFilePreEx.Cells(c, 21) <> "DIVD" Then
myRange = myRange & "," & c & ":" & c
End If
c = c + 1
Loop
ioFilePreEx.Range(Mid(myRange, 2)).Copy Destination:=ioFilePreEx1.Range("A" 
& ioFileLastRow).End(xlUp).Offset(1, 0)
ioFilePreEx.Range(Mid(myRange, 2)).Delete

End Sub