Userform trouble?

lpking2005

Board Regular
Joined
Mar 21, 2011
Messages
140
hi,

in need of some help.....

I currently have a userform which has a textbox which once the user adds text and clicks ok it the populates a textbox on a worksheet.

Also when this userform is initialised, it reads the text from the worksheet textbox.

What i want to do is, instead of creating multiple copies of the userform, can i have it where this userform is linked to about 4 other commandbuttons,
But it only reads and writes textbox values to other textboxes depending on which button I press?

i hope you understand me?
i think i just confused myself:confused::rofl:
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
set up a global variable (eg FRED) as integer
if you have , say, 5 commandbuttons on your sheet, add to each button's click code
FRED = 1, or FRED = 2 etc, so that each one is unique

In the userform initialise routine use
Select case fred
case 1
textbox1.text = sheets("Blah").textbox1.text
case 2
textbox1.text = sheets("Blah").textbox2.text
.
.
end select

Use the same method in reverse when the user clicks OK on the userform
 
Upvote 0
thanks for the reply, but still cannot get it to work, been playing around for 30mins with it, but no luck.


I have this on my command buttons:
Code:
Dim product As Integer

product = 1

OpComments.Show


I have this connected to userform:
Code:
Private Sub UserForm_Initialize()

'open correct product comments

Select Case product
Case 1
CommentsBox.Value = Sheets("OP COMMENTS").NewLF
Case 2
CommentsBox.Value = Sheets("OP COMMENTS").OldLF

End Select

End Sub

and this connected to userform OK button:
Code:
Private Sub CommandButton2_Click()

'set comments into cell

Dim product As Integer

Select Case product
Case 1
Sheets("OP COMMENTS").NewLF = CommentsBox.Value
Case 2
Sheets("OP COMMENTS").OldLF = CommentsBox.Value
End Select


Unload Me

End Sub
 
Upvote 0
Don't Dim product in each button's code.
Use

Code:
Public Product as Integer

at the top of the code in any code module.

To check thast it works, stop the code while the form is loading and check that the value of Product is as expected

Code:
Private Sub UserForm_Initialize()

'open correct product comments
Stop
Select Case product
Case 1
CommentsBox.Value = Sheets("OP COMMENTS").NewLF
Case 2
CommentsBox.Value = Sheets("OP COMMENTS").OldLF

End Select

End Sub

when it stops, hover over Product to check the value
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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