2017-11-10 123 views
0

我有這樣的代碼,因爲我認爲這將其不能正常工作:裝滿值空白單元格

`Sub FillRow() 
    Dim Name As String 
    For Each c In Range("G1:G" & Cells(Rows.Count, 2).End(xlUp).Row) 
     If Cells(c.Row, 1) > "" Then 
     MsgBox ActiveCell.Address 
      Name = Cells(c.Row, 1) 
     Else 
      Cells(c.Row, 1).Value = Name 

     End If 
    Next 
End Sub` 

試圖讓G列空白單元格填充上面的價值和如果它有價值就留下。什麼都沒有發生 - 調試似乎顯示行不增加。我雖然之前工作

+0

你的代碼沒有做任何事。 – SJR

回答

0

你有列錯誤。試試這個:

Sub FillRow() 
    Dim name As String 
    Dim c As Excel.Range 

    For Each c In Range("G1:G" & Cells(Rows.Count, "G").End(xlUp).Row).Cells 
     If Len(CStr(Cells(c.Row, "G").Value2)) > 0 Then 
      name = Cells(c.Row, "G") 
     Else 
      Cells(c.Row, "G").Value = name 
     End If 
    Next 
End Sub 
+0

這有效!謝謝。我確信我之前使用過其他代碼。 –