Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofilter with VB and locked cells doesn't work :( plz help

Status
Not open for further replies.

Bokazoit

Technical User
Sep 16, 2004
73
0
0
DK
I have a small problem (I hope)

I have created an advanced filter using this code:



code:
--------------------------------------------------------------------------------
Sub Filter_Copy()
Worksheets("Kampagneprioritering").Range("N4:AB1004").Delete
Application.ScreenUpdating = False
Sheets("Data").Activate
Names.Add Name:="Raw_Data", RefersTo:=Range("A8:N8", Range("A8:N8").End(xlDown))
Range("Raw_Data").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("A1:D6"), CopyToRange:=Range("Kampagneprioritering!N4"), Unique:=False
Sheets("Kampagneprioritering").Activate
End Sub

--------------------------------------------------------------------------------




It copies the filtered rows from sheet2 ("Data") to sheet1 ("Kampagneprioritering")

Now I need to lock all cells in sheet1 and only allow a few cells in sheet1 to be changed. If I look all cells except for those few, I get an error that says it can't do the delete:

Worksheets("Kampagneprioritering").Range("N4:AB1004").Delete

No matter what I do, even if I allow all possible changes while cells are locked it doesn't do the trick. I'm a little stocked here, and hope for some help. Is there something in my vb code I need to add or?

In advance tx
 
Hi,

Unprotect, then stuff then Protect.
Code:
Sub Filter_Copy()

    With Worksheets("Kampagneprioritering")
        .Unprotect
        .Range("N4:AB1004").Delete
    End With
    Application.ScreenUpdating = False
    With Sheets("Data")
        .Names.Add _
            Name:="Raw_Data", _
            RefersTo:="=" & .Name & "!" & .Range(.Range("A8:N8"), .Range("A8:N8").End(xlDown)).Address
        Range("Raw_Data").AdvancedFilter _
            Action:=xlFilterCopy, _
            CriteriaRange:=.Range("A1:D6"), _
            CopyToRange:=Worksheets("Kampagneprioritering").Range("N4"), _
            Unique:=False
    End With
    Worksheets("Kampagneprioritering").Protect
End Sub


Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top