Excel VBA – 如何使这个单一的循环

我有一段代码包含3 for循环。 我想找出一种方法,可能通过使用数组,使这一个单一的循环。 数据拼凑在一起的方式,4,5,6列没有填充数据。 它的工作,数据应该是什么是填充1行以上。 所以这个代码工作得很好,我只是在寻找一个更有效的编码方式。 谢谢!

For i = 2 To erow If currentSht.Cells(i, 4).Value = "" Then currentSht.Cells(i, 4).Value = currentSht.Cells(i - 1, 4).Value End If Next i For i = 2 To erow If currentSht.Cells(i, 5).Value = "" Then currentSht.Cells(i, 5).Value = currentSht.Cells(i - 1, 5).Value End If Next i For i = 2 To erow If currentSht.Cells(i, 6).Value = "" Then currentSht.Cells(i, 6).Value = currentSht.Cells(i - 1, 6).Value End If Next i 

如何多个For的

 For i = 2 To erow For j = 4 to 6 If currentSht.Cells(i, j).Value = "" Then currentSht.Cells(i, j).Value = currentSht.Cells(i - 1, j).Value End If Next j Next i 

把所有三个IF放在一个循环中:

 For i = 2 To erow If currentSht.Cells(i, 4).Value = "" Then currentSht.Cells(i, 4).Value = currentSht.Cells(i - 1, 4).Value End If If currentSht.Cells(i, 5).Value = "" Then currentSht.Cells(i, 5).Value = currentSht.Cells(i - 1, 5).Value End If If currentSht.Cells(i, 6).Value = "" Then currentSht.Cells(i, 6).Value = currentSht.Cells(i - 1, 6).Value End If Next i