ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Left hanging (https://www.excelbanter.com/excel-programming/310082-left-hanging.html)

Pat[_22_]

Left hanging
 
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



Norman Jones

Left hanging
 
Hi Pat,

Try changing:

rng = rng.Offset(1, 0)



to:

Set rng = rng.Offset(1, 0)

---
Regards,
Norman



"Pat" wrote in message
...
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






All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com