Left hanging

P

Pat

The following code was kindly supplied to me but it fails to run, in fact it
hangs. Anyone know what might be wrong with it.

Private Sub CommandButton1_Click()
Dim rng As Range, lastrow As Long
lastrow = Cells(Rows.Count, 4).End(xlUp).Row
Set rng = Range("D1")
Do While UCase(rng) <> "G" And rng.Row <= lastrow
rng = rng.Offset(1, 0)
Loop
If UCase(rng.Value) = "G" Then
rng.EntireRow.Insert
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top