Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Option Button

I have little knowledge of how to write VB code.
I have a form with 3 option buttons alongside 3 cells for data entry. When
a button is selected I want the corresponding cell to allow data entry and
the other 2 to be locked. Why does this code not work:

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range(i11).Locked = False
Worksheets("PART A").Range("i13:i15,d23:d24").Locked = True
Worksheets("PART A").Protect
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Option Button

This works for me. You were close

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range("I11").Locked = False
Worksheets("PART A").Range("I13:I15,D23:D24").Locked = True
Worksheets("PART A").Protect
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"smcs" wrote in message
...
I have little knowledge of how to write VB code.
I have a form with 3 option buttons alongside 3 cells for data entry.

When
a button is selected I want the corresponding cell to allow data entry and
the other 2 to be locked. Why does this code not work:

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range(i11).Locked = False
Worksheets("PART A").Range("i13:i15,d23:d24").Locked = True
Worksheets("PART A").Protect
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Option Button

Hi Bob

Thanks for your help. I corrected missing quotes, but I am still getting an
error:
"Run time error 1004: Unable to set the Locked property of the Range class"

I am using data validation to limit the number of characters in the cells.

I have tried to recreate the error in a separate spreadsheet with just the 3
buttons and 3 cells, with data validation and it works fine, but I
consistently get the error in my form. I have check the help and none of it
seems to apply. Any suggestions?

"Bob Phillips" wrote:

This works for me. You were close

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range("I11").Locked = False
Worksheets("PART A").Range("I13:I15,D23:D24").Locked = True
Worksheets("PART A").Protect
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"smcs" wrote in message
...
I have little knowledge of how to write VB code.
I have a form with 3 option buttons alongside 3 cells for data entry.

When
a button is selected I want the corresponding cell to allow data entry and
the other 2 to be locked. Why does this code not work:

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range(i11).Locked = False
Worksheets("PART A").Range("i13:i15,d23:d24").Locked = True
Worksheets("PART A").Protect
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Option Button

I have found my problem. The cells that I am referencing are merged cells,
eg I11 is the first cell in the range I11 to R11 which have been merged into
one cell. The problem is fixed by referencing the range that has been merged.

Thanks for your help.

"Bob Phillips" wrote:

This works for me. You were close

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range("I11").Locked = False
Worksheets("PART A").Range("I13:I15,D23:D24").Locked = True
Worksheets("PART A").Protect
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"smcs" wrote in message
...
I have little knowledge of how to write VB code.
I have a form with 3 option buttons alongside 3 cells for data entry.

When
a button is selected I want the corresponding cell to allow data entry and
the other 2 to be locked. Why does this code not work:

Private Sub OptionButton1_Click()
Worksheets("PART A").Unprotect
Worksheets("PART A").Range(i11).Locked = False
Worksheets("PART A").Range("i13:i15,d23:d24").Locked = True
Worksheets("PART A").Protect
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keep source formatting is not an option in paste option button Tina Excel Discussion (Misc queries) 0 February 20th 06 09:58 PM
option button-if else? Alen32 Excel Programming 13 March 23rd 05 08:58 PM
Option button chris_za_za Excel Programming 7 November 1st 04 01:04 PM
When using an Option Button can I... phil[_2_] Excel Programming 3 August 5th 04 11:41 PM
value of option button paradise Excel Programming 1 September 30th 03 04:30 AM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"