View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default How to get row number?

Hi Sam,

After the code where you insert the row, the new row number should be a+1.

--
Regards,

OssieMac


"Sam Kuo" wrote:

I use the "Do Until...Loop" in forms subroutine to insert a row in worksheet
at specified location. How do I get the row number of the new row?


Private Sub cmdInsertRow_Click()

Dim ws As Worksheet
Dim a As Long
Set ws = Worksheets("Sheet1")

a = 22 'data starts at row 22
Do Until Trim(ws.Cells(a, 1)) = ""
If ws.Cells(a, 1) = Me.cboRefValue.Value Then
ws.Cells(a + 1, 1).EntireRow.Insert
a = a + 2
Else
a = a + 1
End If
Loop

End Sub