Auto delete.....

G

gane

Hai I am maintaining a template which having values and blanks. I want to
delete the blank rows. I wrote program as
Sub DelRows()
Dim c As Range

strfind = InputBox("enter value to find and delete")

With Worksheets(1).Range("A:A")
Do
Set c = .Find(strfind, LookIn:=xlValues, lookat:=xlPart, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.EntireRow.Delete
Loop
End With
End Sub

Its working very fine. but the fact is i had locked certain cells and my
worksheet & workbook is password protected. the code above is not working for
this case. Please anyone help me to solve my problem
 
J

JE McGimpsey

One way:

You can unprotect your worksheet in the macro, then protect it again:

Public Sub DelRows()
Const sPWORD As String = "drowssap"
Dim c As Range
Dim strfind As String

strfind = InputBox("enter value to find and delete")

With Worksheets(1)
.Unprotect Password:=sPWORD
With .Range("A:A")
Do
Set c = .Find( _
What:=strfind, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.EntireRow.Delete
Loop
End With
.Protect Password:=sPWORD
End With
End Sub
 
G

gane

thanks itz working great..........

JE McGimpsey said:
One way:

You can unprotect your worksheet in the macro, then protect it again:

Public Sub DelRows()
Const sPWORD As String = "drowssap"
Dim c As Range
Dim strfind As String

strfind = InputBox("enter value to find and delete")

With Worksheets(1)
.Unprotect Password:=sPWORD
With .Range("A:A")
Do
Set c = .Find( _
What:=strfind, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.EntireRow.Delete
Loop
End With
.Protect Password:=sPWORD
End With
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