2017-11-10 124 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

这有效!谢谢。我确信我之前使用过其他代码。 –