Karthik P B
Karthik P B

Reputation: 237

Want to disable a cell from editing if the other cell has a certain value

I want to disable a cell if another call contains certain values, i have written the below piece of code but it is throwing me an error

"Wrong number of argument or invalid property assignment".

Kindly help me to resolve this issue.

Private Sub ComboBox1_Click()
    Dim projworkbook As Workbook
    Dim page1 As Worksheet

    Set projworkbook = ActiveWorkbook
    Set page1 = projworkbook.Worksheets("Project_Creation")

    If Me.ComboBox1.Text = "Extention" Then
        Me.ComboBox2.Visible = True else
        page1.Range("B5").AllowEdit = False '-> I am getting error here
    end if
  End Sub

Upvotes: 1

Views: 629

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

The issue is that .AllowEdit is read only, so you cannot set it to False.

Instead use .Locked = True to lock a range, or accordingly .Locked = False to unlock a range.

Note that the worksheet needs to be protected so that this property is used. By default all ranges are marked as .Locked = True so if you protect a sheet everything gets locked. So you probably need to unlock the ranges you don't want to be locked when you protect the sheet.

Upvotes: 1

Related Questions