0

This is the statement I am currently using. I need to find a way to populate the two rows I've inserted, using the value of the last populated cell before my new empty rows. How do I do this?

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 に答える