VBA 根据其他文本框是否为空更改文本框中的值
VBA Change value in textbox based on whether other textboxes are empty
在这里遇到一些代码问题,寻求帮助。我试图根据另一个文本框是否有值来找出更新文本框值的正确语法。
细分
- Textbox1 名称 = arisk_box
- 文本框 2 名称 = adjust_box3
- Textbox3 名称 = rr_box
这是我目前拥有的:
Private Sub arisk_box_Change()
If arisk_box.Text <> "" And adjust_box3.Text = "" Then
rr_box.Value = arisk_box.Value
ElseIf arisk_box.Text <> "" And adjust_box3.Text <> "" Then
rr_box.Value = adjust_box3.Value
End If
End Sub
*If arisk_box has a *VALUE* and adjust_box3 *DOES NOT* then rr_box = the value from arisk_box
Elseif arisk_box AND adjust_box3 both have a *VALUE* then rr_box = the value from adjust_box3
最简单的方法是使用 2 个单独的宏,一个用于每个文本框更改事件。但它可能无法像您希望的那样顺利运行。我相信有人会有更高级的方法。
Private Sub adjust_box3_Change()
If arisk_box <> "" And adjust_box3 = "" Then rr_box = arisk_box
End Sub
Private Sub arisk_box_Change()
If arisk_box <> "" And adjust_box3 <> "" Then rr_box = adjust_box3
End Sub
在这里遇到一些代码问题,寻求帮助。我试图根据另一个文本框是否有值来找出更新文本框值的正确语法。
细分
- Textbox1 名称 = arisk_box
- 文本框 2 名称 = adjust_box3
- Textbox3 名称 = rr_box
这是我目前拥有的:
Private Sub arisk_box_Change()
If arisk_box.Text <> "" And adjust_box3.Text = "" Then
rr_box.Value = arisk_box.Value
ElseIf arisk_box.Text <> "" And adjust_box3.Text <> "" Then
rr_box.Value = adjust_box3.Value
End If
End Sub
*If arisk_box has a *VALUE* and adjust_box3 *DOES NOT* then rr_box = the value from arisk_box
Elseif arisk_box AND adjust_box3 both have a *VALUE* then rr_box = the value from adjust_box3
最简单的方法是使用 2 个单独的宏,一个用于每个文本框更改事件。但它可能无法像您希望的那样顺利运行。我相信有人会有更高级的方法。
Private Sub adjust_box3_Change()
If arisk_box <> "" And adjust_box3 = "" Then rr_box = arisk_box
End Sub
Private Sub arisk_box_Change()
If arisk_box <> "" And adjust_box3 <> "" Then rr_box = adjust_box3
End Sub