Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a textbox value from a form. 1

Status
Not open for further replies.

wwgmr

MIS
Mar 12, 2001
174
US
Hi all, I tried to search for textbox in forums and found nothing. So I throwing this out.

I have excel sheet where I have added check boxes in 5 rows down and 7 rows across. I have linked each one to a cell so that when you click the Check box(cbHours) it brings up a Userform I have created which will have textbox and okay button. The user will enter in hours into the Text box called txHours and when he clicks Okay I want it to enter that value into the cbHours Linked cell. so I can then use it for a simple Sum on the excel sheet.

I am having problems with the object here as I tried differnent ways to do it and keep getting errors.

There are many check boxes linked to their own cells so I didn't want to write code for a user form for each. That is why I tried to link the Check box to a cell. Maybe there is better way to do this?

Any help would be great! Thanks

 
The LinkedCell property for a checkbox is expected to contain either TRUE or FALSE. You can designate a companion cell by offset from the LinkedCell (by careful coding) to contain the user's input value that you want.

Here is an example for one checkbox using the cell to the right of the LinkedCell to contain the user input:

Sheet1 code (one sub for each of the 35 checkboxes):[blue]
Code:
  Private Sub CheckBox1_Click()
    ProcessCB CheckBox1.LinkedCell
  End Sub
[/color]

A separate code module:[blue]
Code:
  Option Explicit
  Public UserValue As String

  Sub ProcessCB(ALinkedCell As String)
    If Range(ALinkedCell).Value = True Then
      UserValue = Range(ALinkedCell).Offset(0, 1).Value
      UserForm1.Show
      Range(ALinkedCell).Offset(0, 1).Value = UserValue
    End If
  End Sub
[/color]

UserForm1 code:[blue]
Code:
  Option Explicit

  Private Sub UserForm_Activate()
    TextBox1.Value = UserValue
  End Sub

  Private Sub CommandButton1_Click()
    UserValue = TextBox1.Value
    Me.Hide
  End Sub
[/color]

 
Thank you very much Zathras that was what I was looking for. I am adjusting it to work with what I have. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top