Run time error 1004 in VBA Code - the password you supplied is not correct

Vikas1234

New Member
Joined
Aug 20, 2019
Messages
5
Hello Team, I an encountering this error regularly. I tried to debug the code but unable to resolve the error. Request you to guide me to resolve the issue. I have similar file with this code and it is not showing any error. Here is the code for your reference. Please share your response with me on the same.
Code:
Sub Add_New_Period()


Dim numPer As Integer
Dim new_numPer As Integer
Dim wks As Worksheet
Dim strNam As String


Dim chartname As String
Dim objDia As ChartObject, k%


    numPer = ActiveSheet.Range("x22")
    new_numPer = numPer + 1
    strNam = ActiveSheet.Name
    ActiveSheet.Unprotect Password:="SSE"


Sheets("Master Template").Select
ActiveSheet.Unprotect Password:="SSE"
Range("A1:AA599").Select
Selection.Copy


Worksheets(strNam).Select
Range("A1").Select
Selection.Insert Shift:=xlToRight


k = 600
For Each objDia In ActiveSheet.ChartObjects
ActiveSheet.Cells(k, 1) = objDia.Name
k = k + 1
Next


chartname = Range("A" + CStr(k - 1))
Worksheets(strNam).ChartObjects(chartname).Activate
ActiveChart.SetSourceData Source:=Range("Q12:S24")
Worksheets(strNam).Range("X22") = new_numPer


Worksheets(strNam).Range("E1") = "=" + "AF1"
Worksheets(strNam).Range("E4") = "=" + "AF4"


Worksheets("Overview Results current period").Rows(16).Insert
Worksheets("Overview Results current period").Range("A16") = strNam
 
  Worksheets("Overview Results current period").Range("B16") = "=" + "'" + strNam + "'" + "!" + "E4"
  Worksheets("Overview Results current period").Range("C16") = "=" + "'" + strNam + "'" + "!" + "E6"
  Worksheets("Overview Results current period").Range("D16") = "=" + "'" + strNam + "'" + "!" + "S1"
  Worksheets("Overview Results current period").Range("E16") = "=" + "'" + strNam + "'" + "!" + "X1"
  
  Worksheets("Overview Results current period").Range("F16") = "=" + "'" + strNam + "'" + "!" + "Q4"
  Worksheets("Overview Results current period").Range("G16") = "=" + "'" + strNam + "'" + "!" + "Q6"
  Worksheets("Overview Results current period").Range("H16") = "=" + "'" + strNam + "'" + "!" + "Q8"
  Worksheets("Overview Results current period").Range("I16") = "=" + "'" + strNam + "'" + "!" + "Q26"
  Worksheets("Overview Results current period").Range("J16") = "=" + "'" + strNam + "'" + "!" + "AR26"
  Worksheets("Overview Results current period").Range("K16") = "=" + "'" + strNam + "'" + "!" + "Q136"
  Worksheets("Overview Results current period").Range("L16") = "=" + "'" + strNam + "'" + "!" + "AR136"
  
  Worksheets("Overview Results current period").Range("M16").Formula = "=" + "'" + strNam + "'" + "!" + "W26" + "/" + "15"
  Worksheets("Overview Results current period").Range("N16") = "=" + "'" + strNam + "'" + "!" + "Z26"
  Worksheets("Overview Results current period").Range("O16").Formula = "=" + "'" + strNam + "'" + "!" + "V28" + "/" + "5"
  Worksheets("Overview Results current period").Range("P16") = "=" + "'" + strNam + "'" + "!" + "Z28"
  Worksheets("Overview Results current period").Range("Q16").Formula = "=" + "'" + strNam + "'" + "!" + "V55" + "/" + "5"
  Worksheets("Overview Results current period").Range("R16") = "=" + "'" + strNam + "'" + "!" + "Z55"
  Worksheets("Overview Results current period").Range("S16").Formula = "=" + "'" + strNam + "'" + "!" + "V88" + "/" + "5"
  Worksheets("Overview Results current period").Range("T16") = "=" + "'" + strNam + "'" + "!" + "Z88"
  Worksheets("Overview Results current period").Range("U16").Formula = "=" + "'" + strNam + "'" + "!" + "W106" + "/" + "15"
  Worksheets("Overview Results current period").Range("V16") = "=" + "'" + strNam + "'" + "!" + "Z106"
  Worksheets("Overview Results current period").Range("W16").Formula = "=" + "'" + strNam + "'" + "!" + "V108" + "/" + "5"
  Worksheets("Overview Results current period").Range("X16") = "=" + "'" + strNam + "'" + "!" + "Z108"
  Worksheets("Overview Results current period").Range("Y16").Formula = "=" + "'" + strNam + "'" + "!" + "V136" + "/" + "5"
  Worksheets("Overview Results current period").Range("Z16") = "=" + "'" + strNam + "'" + "!" + "Z136"
  Worksheets("Overview Results current period").Range("AA16").Formula = "=" + "'" + strNam + "'" + "!" + "V156" + "/" + "5"
  Worksheets("Overview Results current period").Range("AB16") = "=" + "'" + strNam + "'" + "!" + "Z156"
  Worksheets("Overview Results current period").Range("AC16").Formula = "=" + "'" + strNam + "'" + "!" + "W171" + "/" + "15"
  Worksheets("Overview Results current period").Range("AD16") = "=" + "'" + strNam + "'" + "!" + "Z171"
  Worksheets("Overview Results current period").Range("AE16").Formula = "=" + "'" + strNam + "'" + "!" + "V173" + "/" + "5"
  Worksheets("Overview Results current period").Range("AF16") = "=" + "'" + strNam + "'" + "!" + "Z173"
  Worksheets("Overview Results current period").Range("AG16").Formula = "=" + "'" + strNam + "'" + "!" + "V188" + "/" + "5"
  Worksheets("Overview Results current period").Range("AH16") = "=" + "'" + strNam + "'" + "!" + "Z188"
  Worksheets("Overview Results current period").Range("AI16").Formula = "=" + "'" + strNam + "'" + "!" + "V213" + "/" + "5"
  Worksheets("Overview Results current period").Range("AJ16") = "=" + "'" + strNam + "'" + "!" + "Z213"
  Worksheets("Overview Results current period").Range("AK16").Formula = "=" + "'" + strNam + "'" + "!" + "V244" + "/" + "5"
  Worksheets("Overview Results current period").Range("AL16") = "=" + "'" + strNam + "'" + "!" + "Z244"
  Worksheets("Overview Results current period").Range("AM16").Formula = "=" + "'" + strNam + "'" + "!" + "V232" + "/" + "5"
  Worksheets("Overview Results current period").Range("AN16") = "=" + "'" + strNam + "'" + "!" + "Z232"
  Worksheets("Overview Results current period").Range("AO16").Formula = "=" + "'" + strNam + "'" + "!" + "V236" + "/" + "5"
  Worksheets("Overview Results current period").Range("AP16") = "=" + "'" + strNam + "'" + "!" + "Z236"
  Worksheets("Overview Results current period").Range("AQ16").Formula = "=" + "'" + strNam + "'" + "!" + "V240" + "/" + "5"
  Worksheets("Overview Results current period").Range("AR16") = "=" + "'" + strNam + "'" + "!" + "Z240"
  
  Worksheets("Overview Results all periods").Rows(12).Insert
  Worksheets("Overview Results all periods").Range("A12") = strNam
 
  Worksheets("Overview Results all periods").Range("B12") = "=" + "'" + strNam + "'" + "!" + "E4"
  Worksheets("Overview Results all periods").Range("C12") = "=" + "'" + strNam + "'" + "!" + "E6"
  Worksheets("Overview Results all periods").Range("D12") = "=" + "'" + strNam + "'" + "!" + "S1"
  Worksheets("Overview Results all periods").Range("E12") = "=" + "'" + strNam + "'" + "!" + "X1"


  Worksheets("Overview Results all periods").Range("F12") = "=" + "'" + strNam + "'" + "!" + "Q4"
  Worksheets("Overview Results all periods").Range("G12") = "=" + "'" + strNam + "'" + "!" + "Q6"
  Worksheets("Overview Results all periods").Range("H12") = "=" + "'" + strNam + "'" + "!" + "Q8"
  
  Worksheets("Overview Results all periods").Range("I12") = "=" + "'" + strNam + "'" + "!" + "Q26"
  Worksheets("Overview Results all periods").Range("J12") = "=" + "'" + strNam + "'" + "!" + "AR26"
  Worksheets("Overview Results all periods").Range("K12") = "=" + "'" + strNam + "'" + "!" + "Q136"
  Worksheets("Overview Results all periods").Range("L12") = "=" + "'" + strNam + "'" + "!" + "AR136"
  
  Worksheets("Overview Results all periods").Range("M12").Formula = "=" + "'" + strNam + "'" + "!" + "W26" + "/" + "15"
  Worksheets("Overview Results all periods").Range("N12") = "=" + "'" + strNam + "'" + "!" + "Z26"
  Worksheets("Overview Results all periods").Range("O12").Formula = "=" + "'" + strNam + "'" + "!" + "V28" + "/" + "5"
  Worksheets("Overview Results all periods").Range("P12") = "=" + "'" + strNam + "'" + "!" + "Z28"
  Worksheets("Overview Results all periods").Range("Q12").Formula = "=" + "'" + strNam + "'" + "!" + "V55" + "/" + "5"
  Worksheets("Overview Results all periods").Range("R12") = "=" + "'" + strNam + "'" + "!" + "Z55"
  Worksheets("Overview Results all periods").Range("S12").Formula = "=" + "'" + strNam + "'" + "!" + "V88" + "/" + "5"
  Worksheets("Overview Results all periods").Range("T12") = "=" + "'" + strNam + "'" + "!" + "Z88"
  Worksheets("Overview Results all periods").Range("U12").Formula = "=" + "'" + strNam + "'" + "!" + "W106" + "/" + "15"
  Worksheets("Overview Results all periods").Range("V12") = "=" + "'" + strNam + "'" + "!" + "Z106"
  Worksheets("Overview Results all periods").Range("W12").Formula = "=" + "'" + strNam + "'" + "!" + "V108" + "/" + "5"
  Worksheets("Overview Results all periods").Range("X12") = "=" + "'" + strNam + "'" + "!" + "Z108"
  Worksheets("Overview Results all periods").Range("Y12").Formula = "=" + "'" + strNam + "'" + "!" + "V136" + "/" + "5"
  Worksheets("Overview Results all periods").Range("Z12") = "=" + "'" + strNam + "'" + "!" + "Z136"
  Worksheets("Overview Results all periods").Range("AA12").Formula = "=" + "'" + strNam + "'" + "!" + "V156" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AB12") = "=" + "'" + strNam + "'" + "!" + "Z156"
  Worksheets("Overview Results all periods").Range("AC12").Formula = "=" + "'" + strNam + "'" + "!" + "W171" + "/" + "15"
  Worksheets("Overview Results all periods").Range("AD12") = "=" + "'" + strNam + "'" + "!" + "Z171"
  Worksheets("Overview Results all periods").Range("AE12").Formula = "=" + "'" + strNam + "'" + "!" + "V173" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AF12") = "=" + "'" + strNam + "'" + "!" + "Z173"
  Worksheets("Overview Results all periods").Range("AG12").Formula = "=" + "'" + strNam + "'" + "!" + "V188" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AH12") = "=" + "'" + strNam + "'" + "!" + "Z188"
  Worksheets("Overview Results all periods").Range("AI12").Formula = "=" + "'" + strNam + "'" + "!" + "V213" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AJ12") = "=" + "'" + strNam + "'" + "!" + "Z213"
  Worksheets("Overview Results all periods").Range("AK12").Formula = "=" + "'" + strNam + "'" + "!" + "V244" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AL12") = "=" + "'" + strNam + "'" + "!" + "Z244"
  Worksheets("Overview Results all periods").Range("AM12").Formula = "=" + "'" + strNam + "'" + "!" + "V232" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AN12") = "=" + "'" + strNam + "'" + "!" + "Z232"
  Worksheets("Overview Results all periods").Range("AO12").Formula = "=" + "'" + strNam + "'" + "!" + "V236" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AP12") = "=" + "'" + strNam + "'" + "!" + "Z236"
  Worksheets("Overview Results all periods").Range("AQ12").Formula = "=" + "'" + strNam + "'" + "!" + "V240" + "/" + "5"
  Worksheets("Overview Results all periods").Range("AR12") = "=" + "'" + strNam + "'" + "!" + "Z240"


 ActiveSheet.Protect userinterfaceonly:=True, Password:="SSE"
 ActiveSheet.EnableOutlining = True 'für Gliederung
 ActiveSheet.EnableAutoFilter = True 'für Autofilter
 
 Sheets("Master Template").Select
 ActiveSheet.Protect userinterfaceonly:=True, Password:="SSE"
 ActiveSheet.EnableOutlining = True 'für Gliederung
 ActiveSheet.EnableAutoFilter = True 'für Autofilter
 
 Worksheets(strNam).Select
  End Sub

Thank you
 
Last edited by a moderator:
Just run it independently of the other code.
If the code "isn't working" then the password to unlock the sheets is incorrect.....and with that we can't help you, as we don't assist in breaking / bypassing passwords
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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