0

这是我目前使用的语句。我需要找到一种方法来填充我插入的两行,使用我的新空行之前最后一个填充单元格的值。我该怎么做呢?

Sub Insert_Rows()
Dim r As Long, mcol As String, i As Long, s As Long, ncol As Long

' find last used cell in Column A
  r = Cells(Rows.Count, "A").End(xlUp).Row

 ' get value of  last used cell in column A
  mcol = Cells(r, 1).Value

'find last used cell in Column B
 s = Cells(Rows.Count, "B").End(xlUp).Row

  ' get value of last used cell in Column B
  ncol = Cells(s, 1).Value

 ' insert rows by looping from bottom
  For i = r To 2 Step -1
     If Cells(i, 1).Value <> mcol Then
       mcol = Cells(i, 1).Value
        Rows(i + 1).Insert
    Rows(i + 1).Insert
     End If
  Next i
End Sub
4

1 回答 1

0

插入行后,您可以使用:

Rows(i + 1).Cells(1, 1).Value = "hi.."    'or
Rows(i + 1).Cells(1, 1).Value = mcol
Rows(i + 2).Cells(1, 1).Value = "there"

将值插入这些行的第一个单元格。

于 2013-07-12T14:35:52.107 回答