run time 1004 unable to set the locked property of the range class .cells

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello i am geting a ruin time error 1004 unable to set the locked property of the range class in my code below

What my code is doing is it is unlocking a cell, the cell is merged so i figured just do it for the two cells in which got merged, but it will loop through and go X amount of rows down and X amount of columns over, so should go through the first batch of columns which will have another for loop inside it to go through X amount of rows then go to the next batch column do the same with the rows and so on

is it because of the .cells with the .locked? i saw a lot of .range with .locked is all?

VBA Code:
Sub Unprotect()

Dim entColAmtCol, colNum, SecColOffFourCol, FirstColOffFourCol, rowMultCol, rowNumCol, SG_RowMultCol, rowMult, groupNum, sg, iterAmtCol, i As Integer

Dim page1 As Workbook
Set page1 = Application.ThisWorkbook
Dim page1_ws As Worksheet

Dim page1_list As Worksheet
Set page1_list = page1.Worksheets("List")

Dim num_ent As Integer
num_ent = page1_list.Cells(Rows.count, 2).End(xlUp).Row - 4

Dim main1 As Worksheet
Set main1 = page1.Worksheets("Main")

entColAmtCol = 4
colNum = 4
FirstColOffFourCol = 13
SecColOffFourCol = 14
rowNumCol = 15
rowMultCol = 66
rowMult = 0
iterAmtCol = 11

For i = 1 To num_ent
    For groupNum = 1 To iterAmtCol
    
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol).Locked = False
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).FormulaHidden = False
    
        rowMult = rowMult + rowMultCol

    Next groupNum
Next i

End Sub

Next i

I am getting the run time error here on this line:
main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol).Locked = False
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I attempted to edit it to something like this but instead getting a run time error 1004 application defined or object defined error not sure why

VBA Code:
entColAmtCol = 4
colNum = 4
FirstColOffFourCol = 13
SecColOffFourCol = 14
rowNumCol = 15
rowMultCol = 66
rowMult = 0
iterAmtCol = 11

For i = 1 To num_ent    
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol).Locked = False
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).FormulaHidden = False
Next i
 
Upvote 0
Had to make an edit sorry

FOR THE FIRST POST

VBA Code:
Sub Unprotect()

Dim entColAmtCol, colNum, SecColOffFourCol, FirstColOffFourCol, rowMultCol, rowNumCol, SG_RowMultCol, rowMult, groupNum, sg, iterAmtCol, i As Integer

Dim page1 As Workbook
Set page1 = Application.ThisWorkbook
Dim page1_ws As Worksheet

Dim page1_list As Worksheet
Set page1_list = page1.Worksheets("List")

Dim num_ent As Integer
num_ent = page1_list.Cells(Rows.count, 2).End(xlUp).Row - 4

Dim main1 As Worksheet
Set main1 = page1.Worksheets("Main")

entColAmtCol = 12
colNum = 4
FirstColOffFourCol = 0
SecColOffFourCol = 1
rowNumCol = 15
rowMultCol = 66
rowMult = 0
iterAmtCol = 11

For i = 1 To num_ent
    For groupNum = 1 To iterAmtCol
  
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol).Locked = False
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol)FormulaHidden = False
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).Locked = False
        main1.Cells(rowNumCol + rowMult, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).FormulaHidden = False
  
        rowMult = rowMult + rowMultCol

    Next groupNum
Next i

End Sub

Next i

The second post in the comments the edit basically the same where im changing the number in which the integer equals

VBA Code:
entColAmtCol = 12
colNum = 4
FirstColOffFourCol = 0
SecColOffFourCol = 1
rowNumCol = 15
rowMultCol = 66
rowMult = 0
iterAmtCol = 11

For i = 1 To num_ent  
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol).Locked = False
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol.FormulaHidden = False
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).Locked = False
        Worksheets("Main").Range(15, (((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol).FormulaHidden = False

Next i
 
Upvote 0
looks like it has to be a range set up like example "D15:E15"
Is there a way to implement the way i have it set up with the formula to make it look like the accepted range?

keeping these since the equation selects what column it is but it will always be row 15 then row 81, but the first portion of code from the original post has an equation to loop through the rows so if able to keep that would make the sub smaller but if not its okay

(((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol)
(((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol)


wouldnt know how to write it but like this how the row is determined by the equation then always row 15
Worksheets("Sch P").Range((((i - 1) * (entColAmtCol)) + colNum) + FirstColOffFourCol, 15 : ((i - 1) * (entColAmtCol)) + colNum) + SecColOffFourCol, 15).locked = false
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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