LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tel Tel is offline
external usenet poster
 
Posts: 39
Default Runtime error in Macro.

Hi All,

Just when I thought it was safe.

I've got a problem with a Macro. What I'm seeking to do is create a copy of
the plan "Remediation Plan" and then, if the cell in "E" is blank then
delete the entire row and then check. The full range is from Cell E4 to E34.

I've copied Ron DeBruin's code and it was working but now I get an error
stating: "Run-time error '1004'"

"Delete method of Range class failed"

When I run "debug" it is the row stating "FoundCell.EntireRow.Delete"
(marked with a * on my code below - the * isn't part of the code) which is
highlighted.

The idea is to give the user a shortened version of the worksheet whereby if
the cell in column "E" is blank they don't need it.


Sub Copy_RM_Plan()
'
' Copy_RM_Plan Macro
' Macro recorded 26/06/2009 by Terry B Glover
'

'
Sheets("Remediation Plan").Select
Application.CutCopyMode = False
Sheets("Remediation Plan").Copy

Dim calcmode As Long
Dim ViewMode As Long
Dim myStrings As Variant
Dim FoundCell As Range
Dim I As Long
Dim myRng As Range
Dim sh As Worksheet

With Application
calcmode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'We use the ActiveSheet but you can also use Sheets("MySheet")
Set sh = ActiveSheet

'We search in column A in this example
Set myRng = sh.Range("E4:E34")

'Add more search strings if you need
myStrings = Array("")


With sh

'We select the sheet so we can change the window view
.Select

'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False

'We will search the values in MyRng in this example
With myRng

For I = LBound(myStrings) To UBound(myStrings)
Do
Set FoundCell = myRng.Find(What:=myStrings(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'Use xlPart If you want to search in a part of the
FoundCell
'If you use LookIn:=xlValues it will also delete rows
with a
'formula that evaluates to "Ron"
If FoundCell Is Nothing Then
Exit Do
Else
* FoundCell.EntireRow.Delete
End If
Loop
Next I

End With

End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With


End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Runtime Error 1004... help? Derrick Excel Discussion (Misc queries) 6 June 24th 09 03:04 PM
Macro runtime error 1004 with Autofilter Lorna B Excel Discussion (Misc queries) 3 May 25th 07 08:38 PM
macro Runtime Error Dave 2005 Excel Discussion (Misc queries) 1 October 18th 05 10:02 PM
Runtime error for macro that works in workbook created in Crystal Excel Discussion (Misc queries) 1 June 22nd 05 08:43 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"