Vba 使用UserForm上的选项按钮将文本放置在调用UserForm的子窗体的范围内
如果这是在别处发布的,我很抱歉,但是我在理解调用用户表单的子控件和用户表单控件之间的关系时遇到了问题。我有一个子系统,可以将数据从另一个工作表填充到工作表中。需要填写的单元格之一是对项目数量变化的解释。我生成了一个带有选项按钮的用户表单,用户可以从中选择适当的“原因”。单击“确定”按钮后,将在工作表的单元格中放置所选原因 在sub中,我使用范围中的每个单元格填充行中特定条件以上每个值的数据,它应该显示符合条件的每个单元格的表格。我是否可以将用作行引用的单元格传递到用户表单中,以便它可以使用该单元格作为偏移量输入所选的“原因”,然后卸载表单Vba 使用UserForm上的选项按钮将文本放置在调用UserForm的子窗体的范围内,vba,excel,Vba,Excel,如果这是在别处发布的,我很抱歉,但是我在理解调用用户表单的子控件和用户表单控件之间的关系时遇到了问题。我有一个子系统,可以将数据从另一个工作表填充到工作表中。需要填写的单元格之一是对项目数量变化的解释。我生成了一个带有选项按钮的用户表单,用户可以从中选择适当的“原因”。单击“确定”按钮后,将在工作表的单元格中放置所选原因 在sub中,我使用范围中的每个单元格填充行中特定条件以上每个值的数据,它应该显示符合条件的每个单元格的表格。我是否可以将用作行引用的单元格传递到用户表单中,以便它可以使用该单元
Private Sub okbutton1_Click(bc As Range) 'bc should be the range from the sub calling this form
Select Case True
Case OptionButton1
If bc.Offset(0, 3).Value = "A" Then
Set bc.Offset(0, 6).Value = "Actual amount required is more than plan quantity."
Else
Set bc.Offset(0, 6).Value = "Actual amount required is less than plan quantity."
End If
Case OptionButton2
Set bc.Offset(0, 6).Value = "This items was not constructed/used/required."
Case OptionButton3
Set bc.Offset(0, 6).Value = "Only a portion of the contingency was required for items not in original plan."
Case OptionButton4
Set bc.Offset(0, 6).Value = "Deficiency levied against Contractor per IDOT Section 105.03."
Case OptionButton5
Set bc.Offset(0, 6).Value = "Damages levied against Contractor per IDOT Section 108.09."
Case OptionButton6
Set bc.Offset(0, 6).Value = InputBox("Please enter your reasoning below.", "Other")
End Select
Unload AuthReason2
End Sub
然后,这是我用来填充工作表的sub的一部分
Line5: 'Populates the BLR13210A from the data entered on the BLR13210
Application.ScreenUpdating = False
Dim bws As Worksheet
Set bws = Worksheets("BLR 13210A")
Dim Arange As Range
Set Arange = aws.Range("AZ34:AZ198")
Dim Bcell As Range ' First cell in AttachA form
Set Bcell = bws.Range("B11")
For Each ACell In Arange
If ACell.Value > 1999.99 Then
Bcell.Value = ACell.Offset(0, -47).Value
Bcell.Offset(0, 1).Value = ACell.Value
Bcell.Offset(0, 2).Value = ACell.Offset(0, -37).Value
Bcell.Offset(0, 3).Value = ACell.Offset(0, -22).Value
AuthReason2(Bcell).Show
End If
Bcell = Bcell.Offset(1, 0)
Application.ScreenUpdating = True
提前感谢您的帮助。应使用用户表单检索用户输入,并将其传递给相应处理数据的处理子系统 所以你最好反其道而行之,即:
- 你的主要潜艇
应该“启动”用户表单并从中检索数据,处理这些数据以作用于其他数据,然后关闭用户表单
可能是这样的:
Option Explicit Sub main() Dim bws As Worksheet Set bws = Worksheets("BLR 13210A") Dim Bcell As Range ' First cell in AttachA form Set Bcell = bws.Range("B11") With UserForm1 '<--| change "UserForm1" to your actual userform name .Tag = Bcell.Offset(0, 3).Value '<--| store the value you want to share with Userform in its 'Tag' property .Show '<-- show the userform and have it process user inputs Bcell.Offset(0, 6).Value = .Tag '<--| retrieve the value that userform has left in its 'Tag' property accordingly to user inputs End With Unload UserForm1 '<--| change "UserForm1" to your actual userform name End Sub
Option Explicit Private Sub okbutton1_Click() Dim txt As String With Me '<--| reference the userform Select Case True Case .OptionButton1 '<--| with the dot (.) access the referenced object members (in this case its controls) If .Tag = "A" Then '<--| query the value that the calling sub has left in the useform 'Tag' property txt = "Actual amount required is more than plan quantity." Else txt = "Actual amount required is less than plan quantity." End If Case .OptionButton2 txt = "This items was not constructed/used/required." Case .OptionButton3 txt = "Only a portion of the contingency was required for items not in original plan." Case .OptionButton4 txt = "Deficiency levied against Contractor per IDOT Section 105.03." Case .OptionButton5 txt = "Damages levied against Contractor per IDOT Section 108.09." Case .OptionButton6 txt = InputBox("Please enter your reasoning below.", "Other") Case Else '<--| you may want to handle the case when the user dosen't select any option txt = "some text" '<--| change it to your needs End Select .Tag = txt '<--| use 'Tag' property to store the value you want to pass back to the calling sub .Hide '<--| hide the userform End With End Sub