在另一个子中引用InputBox值

时间:2020-12-31 00:10:30

In the below code, I have the user choose a cell and have that value go into a textbox within a userform as well as input "Ready for Return" into the cell 13 columns over.

在下面的代码中,我让用户选择一个单元格,并让该值进入userform中的一个文本框,并将“准备返回”输入到单元格的13列中。

Instead of having the string be inputted every time a cell is selected, I would like the string to only be inputted once a command button is pressed. Basically, I want to place the section UserInput1.Offset(0, 13) = "Request Cancelled" under a command button sub within a userform. Is there anyway to reference the range of an inputbox in another sub? Thanks!

我不希望每次选择单元格时都输入字符串,而是希望在按下命令按钮后才输入字符串。基本上,我想要放置section UserInput1。Offset(0,13) = userform中命令按钮子下的“请求取消”。是否存在引用另一个子库的输入框的范围?谢谢!

Private Sub TextBox1_DropButtonClick()

Application.DisplayAlerts = False
Worksheets("Sample Transfer Log").Activate
Set UserInput1 = Application.InputBox(prompt:="Please select a sample transfer request # for return", Title:="Select Request #", Type:=8)
If UserInput1 = False Then
   Exit Sub
Else
    TextBox1.Text = UserInput1
    UserInput1.Offset(0, 13) = "Ready for Return"
    Application.DisplayAlerts = True
End If

End Sub

1 个解决方案

#1


1  

As pointed out by Sorceri in the comments:

正如我在评论中所指出的:

you would need to keep the value in a global variable to access in another sub

您需要将值保存在全局变量中,以便在另一个子中访问

#1


1  

As pointed out by Sorceri in the comments:

正如我在评论中所指出的:

you would need to keep the value in a global variable to access in another sub

您需要将值保存在全局变量中,以便在另一个子中访问