View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default InputBox method with range

Does this sound like a situation you have on your worksheet:

http://www.jkp-ads.com/Articles/SelectARange.asp

--
Regards,
Tom Ogilvy


"Emily Edgington" wrote in
message ...
Thanks, Tom, but I can still replicate the problem with that code. I have
determined that I consistently have the issue when I select all rows below
row 6. For example, my spreadsheet may have values from A7:E40, and I can
select A10:E12 for deletion and it works, but if I choose the entire block
(A7:E40), my Target value equals Nothing, and no deletion occurs.

"Tom Ogilvy" wrote:

Try it this way:

Sub Delete_Rows()

Dim Target As Range
Dim SpecialRows() As Integer
Dim i As Integer
Dim BadRowsList As String
Dim CancelDel As Boolean
Dim EndCleared As Range

CancelDel = False


Title = " "
Prompt = "Select row (or range of rows) to be deleted."
On Error Resume Next
Set Target = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8)
On Error goto 0
If Target Is Nothing Then
Exit Sub
Else
Application.ScreenUpdating = False
ReDim SpecialRows(Target.Rows.Count - 1) As Integer
i = 0
Worksheets(1).Unprotect ("support")
For Each rw In Target.Rows
If rw.Row < 7 Then
SpecialRows(i) = rw.Row
i = i
CancelDel = True
End If
Next
If CancelDel = True Then
MsgBox "Rows 1 - 6 cannot be deleted."
Else
Target.EntireRow.Delete
End If
Worksheets(1).Protect ("support")
End If
Application.ScreenUpdating = True

End Sub

--
Regards,
Tom Ogilvy

"Emily Edgington" wrote:

Actually, I did change it after the original posting - from Target to
myRange, and I still have the issue.

"stevebriz" wrote:

I have tried you macro and it works perfectly...no problem..(office
2003) with or without the error handler.
try changing the word target to something else I am worried that
Target defined elsewhere
let us know how you get on..