2016-01-25 37 views
0

我想通過單擊宏按鈕逐個複製項目,並且消息框將成爲每個項目的中斷。在宏讀取#Value!之前,它會停止複製。如何創建一個可以逐個複製項目的宏?

例子:

A 

    B 

    C 

    D 

#Value! 

我創建了一個VBA這樣的:

Sub Copylineitems() 
    Dim i As Integer 

    Do 

    Sheets("Capital Line Items").Range(Cells(i + 2, 11), Cells(i + 2, 13)).Copy 

    MsgBox "copy" 

     i = 1 + i 


     Loop While Range("K" & (i + 3)) = "#VALUE!" 


      End Sub 

然而,這種編碼是行不通的。

有人可以提醒嗎?

回答

0

本小節可能適用於您。試試下面的子....

Sub CopyItems() 
Dim LastUsedCell As Long 
    LastUsedCell = Sheets("Sheet1").Range("A1").End(xlDown).Row 

    For Each cel In Range("A1:A" & LastUsedCell) 
     If IsError(cel.Value) Then 
      Exit For 
     Else 
      MsgBox cel.Value 
     End If 
    Next 
End Sub 
0

只有幾步調整,你的代碼和代碼@ harun24hr ..

Sub Copylineitems() 
    Dim i As Integer 
    i = 0 
    Do 
     Range(Cells(i + 2, 11), Cells(i + 2, 13)).Copy 
     MsgBox "copy" 
     i = 1 + i 
    Loop While Not IsError(Cells(i + 2, 11).Value) 

End Sub 
相關問題