+ Reply to Thread
Results 1 to 4 of 4

Macro VBA Error 1004 - Insert Method of range class failed

  1. #1
    Registered User
    Join Date
    11-29-2023
    Location
    USA
    MS-Off Ver
    Excel
    Posts
    10

    Lightbulb Macro VBA Error 1004 - Insert Method of range class failed

    Pop up error "Microsoft Virtual Basic - Run-Time error '1004' Insert method of range class failed'. When I hit debug, it highlights the following macro line "MacroSaver Macro
    '

    '
    'Sheets("Saved Data").Select
    ' Rows("2:2").Select
    ' Selection.insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ' Range("A2") = Date
    ' Range("B2") = Format(Now, "HH:MM Am/Pm")"


    There are multiple team members that access/update the tan cells and are supposed to hit the big save button on sheet 1, which saves certain data and reflects it onto sheet 2. When the save button is hit, it will not save/update, but instead gives the error 1004. I have currently set the formulas to automatic, and macros turned off for the sake of the team. These are typically reversed while causing this error.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Macro VBA Error 1004 - Insert Method of range class failed

    This happens because your sheet "Saved Data" is Protected. You need to .UnProtect it at the beginning of the macro and .Protect it once again before the end.
    Difficult is not to know but to share what you know (Han Fei Tzu reworked)

  3. #3
    Registered User
    Join Date
    11-29-2023
    Location
    USA
    MS-Off Ver
    Excel
    Posts
    10

    Re: Macro VBA Error 1004 - Insert Method of range class failed

    Thank you, Rollis. I wanted to make certain that I have the protect/unprotect in the correct spot. I kept being met with the 'end with after the date/time updates. I'm thinking this was causing it to protect again, but I attempted to add the 'end with at the end but didn't seem to fix it. In addition to this, when I do get the save function to run, It seems other users see 'zeros' in the data points where I see values. Same for me seeing zeros when they see values.

    Sub MacroSaver()
    '
    ' MacroSaver Macro
    '

    '
    'Sheets("Saved Data").Select
    ' Rows("2:2").Select
    ' Selection.insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ' Range("A2") = Date
    ' Range("B2") = Format(Now, "HH:MM Am/Pm")

    With Worksheets("Saved Data")
    .Unprotect
    .Rows(2).insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    .Range("A2") = Date
    .Range("B2") = Time
    .Range("B2").NumberFormat = "h:mm AM/PM"

    'End With

    Sheets("Capacity").Select
    Range("F19").Select
    Sheets("Saved Data").Select
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[10]C[-1]"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[10]C[-1]"
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[10]C[-1]"
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[10]C[-1]"
    Range("G2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[11]C[-5]"
    Range("H2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[11]C[-5]"
    Range("I2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[11]C[-5]"
    Range("J2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[11]C[-5]"
    Range("K2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[12]C[-9]"
    Range("L2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[12]C[-9]"
    Range("M2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[12]C[-9]"
    Range("N2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[12]C[-9]"
    Range("O2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[13]C[-13]"
    Range("P2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[13]C[-13]"
    Range("Q2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[13]C[-13]"
    Range("R2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[13]C[-13]"
    Range("S2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[16]C[-17]"
    Range("T2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[16]C[-17]"
    Range("U2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[17]C[-19]"
    Range("V2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[23]C[-15]"
    Range("W2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[23]C[-13]"
    Range("X2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("Y2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("Z2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("AA2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("AB2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("AC2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-22]"
    Range("AD2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-21]"
    Range("AE2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-21]"
    Range("AF2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-21]"
    Range("AG2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[24]C[-21]"
    Range("AH2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[25]C[-30]"
    Range("AI2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[25]C[-30]"
    Range("AJ2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AK2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AL2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AM2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AN2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AO2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-34]"
    Range("AO3").Select
    ActiveWindow.SmallScroll ToRight:=0
    Range("AP2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-32]"
    Range("AQ2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-32]"
    Range("AR2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[29]C[-32]"
    Range("AS2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[33]C[-43]"
    Range("AT2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[33]C[-43]"
    Range("AU2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[33]C[-43]"
    Range("AV2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[33]C[-43]"
    Range("AW2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[34]C[-47]"
    Range("AX2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[34]C[-47]"
    Range("AY2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[34]C[-47]"
    Range("AZ2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[34]C[-47]"
    Range("BA2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[35]C[-51]"
    Range("BB2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[35]C[-51]"
    Range("BC2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[35]C[-51]"
    Range("BD2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[35]C[-51]"
    Range("BE2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[36]C[-55]"
    Range("BF2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[36]C[-55]"
    Range("BG2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[36]C[-55]"
    Range("BH2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[36]C[-55]"
    Range("BI2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[37]C[-58]"
    Range("BJ2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[37]C[-57]"
    Range("BK2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[39]C[-60]"
    Range("BL2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[39]C[-59]"
    Range("BL3").Select
    Sheets("Capacity").Select
    Range("G3:H3").Select
    ActiveCell.FormulaR1C1 = "=NOW()"
    Range("B20").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
    Range("B22").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("C20").Select
    ActiveCell.FormulaR1C1 = "=R[-2]C"
    Range("C22").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("B28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("B30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("C28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("C30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("D28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("D30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("E28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("E30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("F28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("F30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("G28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-2]C)"
    Range("G30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("H28").Select
    ActiveCell.FormulaR1C1 = "=SUM(RC[-6]:RC[-1])"
    Range("H30").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
    Range("I28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("I30").Select
    ActiveCell.FormulaR1C1 = "=R[-2]C/R[-1]C"
    Range("J28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("J30").Select
    ActiveCell.FormulaR1C1 = "=R[-2]C/R[-1]C"
    Range("K28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C)"
    Range("K30").Select
    ActiveCell.FormulaR1C1 = "=R[-2]C/R[-1]C"
    Range("L28").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C)"
    Range("L30").Select
    ActiveCell.FormulaR1C1 = "=R[-2]C/R[-1]C"
    Range("B40").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-5]C:R[-2]C)"
    Range("C40").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
    Range("D40").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-5]C:R[-2]C)"
    Range("E40").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
    Range("F40").Select
    ActiveCell.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
    Range("M30:M31").Select
    ActiveCell.FormulaR1C1 = _
    "=SUM(R[1]C[-11]:R[1]C[-6],R[1]C[-3],R[1]C[-2],R[1]C[-1],R[11]C[-10],R[11]C[-8])"
    Range("N30:O31").Select
    ActiveCell.FormulaR1C1 = _
    "=SUM(R[-18]C[-10],R[-4]C[-4]:R[-4]C[-2],R[9]C[-11],R[9]C[-9])"
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[26]C[6],R[26]C[7],R[26]C[8],R[38]C[4])"
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[25]C[6])"
    Range("C3").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]/144"
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[25]C[3]-R[24]C[3])+(R[25]C[2]-R[24]C[2])"
    Range("B5").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[24]C[6]-R[23]C[6])"
    Range("B6").Select
    ActiveCell.FormulaR1C1 = "=R[22]C[7]"
    Range("C6").Select
    ActiveCell.FormulaR1C1 = "=SUM(RC[-1]/24)"
    Range("B7").Select
    ActiveCell.FormulaR1C1 = _
    "=SUM(R[19]C[5],R[19]C[8],R[19]C[9],R[19]C[10],R[32]C[1],R[32]C[3])"
    Range("B9").Select
    ActiveCell.FormulaR1C1 = "=R[21]C[11]"
    Range("B10").Select
    Sheets("Saved Data").Select
    Range("BM2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[28]C[-52]"
    Range("BN2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[28]C[-52]"
    Range("BO2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[16]C[-59]"
    Range("BO3").Select
    Range("J8").Select
    Sheets("Saved Data").Select
    Range("BS2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[6]C[-69]"
    Range("BS3").Select
    Range("I7").Select
    Sheets("Saved Data").Select
    Range("BP2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[17]C[-60]"
    Range("BQ2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[18]C[-61]"
    Range("BR2").Select
    ActiveCell.FormulaR1C1 = "=Capacity!R[19]C[-62]"
    Range("BR3").Select
    .Protect
    End With
    End Sub

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Macro VBA Error 1004 - Insert Method of range class failed

    It's okay where you put the Unprotect/Protect code and where you moved the End With. What could be pointed out is that you have a lot of redundant Select/Activecell coding, but this is due to the use of the macro recorder.
    Sorry, can't replicate your 'zeros' issue, but in any case it has nothing to do with the Unprotect/Protect patch and the title of this thread.
    Last edited by rollis13; 02-06-2024 at 11:24 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Getting error 1004 Select method of range class failed when i automatically run my macro
    By cubangt in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-2021, 06:14 PM
  2. [SOLVED] Run time error 1004: Autofilter method of range class failed in personal macro workbook.
    By Asad Mir in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2020, 02:04 PM
  3. [SOLVED] Macro Error on Filtering – “Run-time error ‘1004’ Autofilter method of range class failed
    By kschmit1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2019, 11:49 AM
  4. ERROR 1004: Method Of Range Class Failed.
    By Mathijs.Marketing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2018, 04:16 AM
  5. PasteSpecial method of range class failed error 1004
    By iwannabakat in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-05-2014, 08:51 PM
  6. Runtime error 1004: Insert method of Range class failed......not sure why
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-21-2011, 02:15 PM
  7. Error 1004: Pastespecial method of range class failed, macro works sometimes!
    By sam0287 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-19-2009, 09:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1