Run time error 1004: says sheet protected when it is not

alveeru

New Member
Joined
Mar 14, 2018
Messages
3
Hi All i have two issue in below code.

1. its give me Run time error 1004: cannot proceed as sheet is protected, when it is not protected.
2. i want it to run from 3 sheet to run till last sheet,,,but it is keep running on 1 sheet only.

Code:
Sub MacroTest()


Dim i As Integer


    For i = 3 To Worksheets.Count
    Application.DisplayAlerts = False
    Sheets(i).Activate
'    Sheets(i).Unprotect "conso"
    Columns("A:A").EntireColumn.Select
    Selection.TextToColumns Destination:=ActiveCell, DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="*", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
        DecimalSeparator:=",", ThousandsSeparator:=".", TrailingMinusNumbers:= _
        True
    ActiveCell.Range("A1").Select
    Cells.Replace What:="=-", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    ActiveCell.Columns("E:I").EntireColumn.Select
    ActiveCell.Columns("E:I").EntireColumn.EntireColumn.AutoFit
    Application.DisplayAlerts = True


    Next i






End Sub

please help!!
 
Last edited by a moderator:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Does this work any better?
Code:
Sub MacroTest()
Dim I As Long

    Application.DisplayAlerts = False

    For I = 3 To Worksheets.Count
        With Sheets(I)
            .Unprotect "conso"
            With .Columns("A:A").EntireColumn
                .TextToColumns Destination:=.Cells(1, 1), DataType:=xlDelimited, _
                    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
                    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
                    :="*", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
                    DecimalSeparator:=",", ThousandsSeparator:=".", TrailingMinusNumbers:= _
                    True
            End With
        
            .Cells.Replace What:="=-", Replacement:="", LookAt:=xlPart, SearchOrder _
            :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        
            .Columns("E:I").EntireColumn.EntireColumn.AutoFit
            
        End With
    
    Next I
    
    Application.DisplayAlerts = True
    
End Sub
 
Upvote 0
Hi Noori, thank you for your time and help...but i am still facing same issue...

"Run time error 1004: you can not use this command on a protected sheet...etc..."

but my excel file or sheet is not in protected mode.

please help!
 
Upvote 0
Can you post the code you tried and indicate where you get the error?

PS Where is the code located?
 
Upvote 0
Can you post the code you tried and indicate where you get the error?

PS Where is the code located?


here is code:

Sub MacroTest()
Dim I As Long


Application.DisplayAlerts = False


For I = 3 To Worksheets.Count
With Sheets(I)
' .Unprotect "conso"
With .Columns("A:A").EntireColumn
.TextToColumns Destination:=.Cells(1, 1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="*", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
DecimalSeparator:=",", ThousandsSeparator:=".", TrailingMinusNumbers:= _
True
End With

.Cells.Replace What:="=-", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

.Columns("E:I").EntireColumn.EntireColumn.AutoFit

End With

Next I

Application.DisplayAlerts = True

End Sub


i am getting stuck at red part.....
 
Upvote 0
Why is this commented out?
Code:
'.Unprotect "conso"
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,710
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top