Would like to access a textbox in userform to another module

ArnMan

Board Regular
Joined
Aug 30, 2017
Messages
69
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I have a user form with a textbox. and I have a module I cant seem to get the value from the textbox in the userform and use it in another module, I have tried several different codes and cant seem to get it to work.

Here is my userform:

I am able to use msgbox to display the text to make sure my OpCheck variable is working.
Code:
Private Sub AddOpChecks_Click()
Call Blank
Call OperationalPassFail
Call Blank
If OperationChecks.CheckBox1.Value = True Then
OpText = OperationChecks.TextBox1.Text
MsgBox OpText
Call PassFailRow1
Call ChangeSwap
End If

If OperationChecks.CheckBox2.Value = True Then
OpText = OperationChecks.TextBox2.Text
MsgBox OpText
Call PassFailRow1
Call ChangeSwap
End If

End Sub

And here is my module that I want to add the text to a cell:
I can use
Code:
ColB.Value = OperationChecks.TextBox1.Text
and that works, but I am going to use a loop of some sort because I will have more textboxes in my userform that may or may not be used. Each checked, textbox will rerun the below module. So hopefully the OpText variable will display the correct text.
Code:
Sub PassFailRow1()
    Call lRows
    
    Sheets("Sheet1").Range("B" & lRow & ":" & "N" & lRow).Clear
      
    Call BCol
    
    'AAA Column
    ColA.Font.Color = White
    ColA.Value = "1"
    
    
    'B Column
    
    Range(ColB, "E" & lRow).Merge
    ColB.HorizontalAlignment = xlRight
    
    'ColB.Value = OperationChecks.TextBox1.Text
    MsgBox OpText
    ColB.Value = OpText
    
    'C Column
    
    
    Call ChangeSwap
    
    
    
    
 
End Sub

So any help well be greatly appreciated. And I thank you just for taking the time to read my posts.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,
Pass the value as an argument


e.g

Your userform code

Rich (BB code):
Private Sub AddOpChecks_Click()
'declare variables
    Dim OpText As String
    
    'your code
    
    
    
    Call PassFailRow1(OpText)






End Sub


Standard module code

Rich (BB code):
Sub PassFailRow1(ByVal Text As String)
    
    MsgBox Text
    
    
End Sub


Dave
 
Upvote 0
Oh my that worked flawlessly. Thank you for helping me. I haven't used that process, and probably need to remember this

Thank you again. You are the best.

Hi,
Pass the value as an argument


e.g

Your userform code

Rich (BB code):
Private Sub AddOpChecks_Click()
'declare variables
    Dim OpText As String
    
    'your code
    
    
    
    Call PassFailRow1(OpText)






End Sub


Standard module code

Rich (BB code):
Sub PassFailRow1(ByVal Text As String)
    
    MsgBox Text
    
    
End Sub


Dave
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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