2015-04-08 56 views
-3

嗨我需要複製特定範圍的單元格並遍歷行並繼續複製過程,直到遇到空值。難以得到代碼 請幫助值的複製範圍

+0

至少建立自己的代碼的一部分。零件可以很容易地找到谷歌。 –

+0

使用'Do While'來循環,'If'來檢查單元是否爲'null','Exit Do'來退出循環。見[這個問題](http://stackoverflow.com/questions/10933425/loop-through-rows-in-an-excel-worksheet-and-copy-a-range-if-the-cell-isnt-blank? rq = 1)這是相似的。 – mins

+0

我沒有構建代碼,但無法遍歷行。 – Sherly

回答

0

試試這個

Dim rng As Range, cell As Range 
Set rng = Range("A1:B4") 
    ' loop trought each row in selected column Columns(1) = first column in range 
    For Each onlyDefinedColumnRow In rng.Columns(1).Rows 
     If IsEmpty(onlyDefinedColumnRow) Then Exit For 
    i = i + 1 
    Next onlyDefinedColumnRow 
    ' or loop trought each cell in range 
    'For Each cell In rng.Rows 
    ' If IsEmpty(cell) Then Exit For 
    'i = i + 1 
    'Next cell 

rng.Resize(i).Copy Destination:=Cells(i + 2, 1)