2015-04-08 57 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)