#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Error 1004

Hi! I have a button which I use to delete ceratin rows from several sheets in
a workbook. If the button is pressed the user shall enter a date and the code
finds the rows for that date and deletes them .This used to work but now I
get "Error 1004. The Delete methd in Range class failed.". I dont know what
has gone wrong. It gives me error on the row sh_Rows(i).Delete

Public Sub deleteRow()
'deletes all rows for certain dates
Dim sh_ As Worksheet
Dim i As Long
Dim intAnswer As Integer
Dim strDate As String
Dim strPswTry As String
Dim strPsw As String

strPsw = "sombrero"

strDate = Application.InputBox(prompt:="Which date do you want to delete?",
Type:=2)
If strDate < "Falskt" Then
strPswTry = Application.InputBox(prompt:="Enter password", Type:=2)
'If strPswTry = strPsw Then
MsgBox "Password correct."
For Each sh_ In ActiveWorkbook.Sheets
For i = sh_.Cells(65536, 1).End(xlUp).Row To 1 Step -1
If sh_.Cells(i, 1).Value = strDate Then
sh_.Rows(i).Delete
End If
Next i
Next sh_
'End If
MsgBox "Password incorrect."
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Error 1004

On Dec 5, 10:45 am, Arne Hegefors
wrote:
Hi! I have a button which I use to delete ceratin rows from several sheets in
a workbook. If the button is pressed the user shall enter a date and the code
finds the rows for that date and deletes them .This used to work but now I
get "Error 1004. The Delete methd in Range class failed.". I dont know what
has gone wrong. It gives me error on the row sh_Rows(i).Delete

Public Sub deleteRow()
'deletes all rows for certain dates
Dim sh_ As Worksheet
Dim i As Long
Dim intAnswer As Integer
Dim strDate As String
Dim strPswTry As String
Dim strPsw As String

strPsw = "sombrero"

strDate = Application.InputBox(prompt:="Which date do you want to delete?",
Type:=2)
If strDate < "Falskt" Then
strPswTry = Application.InputBox(prompt:="Enter password", Type:=2)
'If strPswTry = strPsw Then
MsgBox "Password correct."
For Each sh_ In ActiveWorkbook.Sheets
For i = sh_.Cells(65536, 1).End(xlUp).Row To 1 Step -1
If sh_.Cells(i, 1).Value = strDate Then
sh_.Rows(i).Delete
End If
Next i
Next sh_
'End If
MsgBox "Password incorrect."
End If
End Sub


Hi
You will get this error if the sheet or cells on it are protected.
Your code works fine for me on an unprotected sheet.
regards
Paul
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Error 1004

Hi Arne -

I get the same result as Paul. Your code works fine unless sheet is
protected and contains a matching date.

---
Jay

"Arne Hegefors" wrote:

Hi! I have a button which I use to delete ceratin rows from several sheets in
a workbook. If the button is pressed the user shall enter a date and the code
finds the rows for that date and deletes them .This used to work but now I
get "Error 1004. The Delete methd in Range class failed.". I dont know what
has gone wrong. It gives me error on the row sh_Rows(i).Delete

Public Sub deleteRow()
'deletes all rows for certain dates
Dim sh_ As Worksheet
Dim i As Long
Dim intAnswer As Integer
Dim strDate As String
Dim strPswTry As String
Dim strPsw As String

strPsw = "sombrero"

strDate = Application.InputBox(prompt:="Which date do you want to delete?",
Type:=2)
If strDate < "Falskt" Then
strPswTry = Application.InputBox(prompt:="Enter password", Type:=2)
'If strPswTry = strPsw Then
MsgBox "Password correct."
For Each sh_ In ActiveWorkbook.Sheets
For i = sh_.Cells(65536, 1).End(xlUp).Row To 1 Step -1
If sh_.Cells(i, 1).Value = strDate Then
sh_.Rows(i).Delete
End If
Next i
Next sh_
'End If
MsgBox "Password incorrect."
End If
End Sub


Reply
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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
runtime error '1004' application or object defined error Janis Excel Programming 4 November 18th 09 03:01 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 06:51 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"