gpt4 book ai didi

vba - VBA循环宏不显示任何错误,但启动后不显示任何结果

转载 作者:行者123 更新时间:2023-12-03 07:53:00 25 4
gpt4 key购买 nike

我正在尝试提出一种用户表格,在其中输入数据,并在按下按钮后自动将其移至表格。

我的用户表单由两个选项按钮(以帮助区分输入数据的位置)和两个文本框组成:一个用于输入条件,另一个用于输入日期,必须将其放入符合条件的单元格中。到目前为止,我想到了以下代码:

Private Sub UzdarytiCB_Click() 

Dim i As Long
'setting conditions for first option button selection
If OptionButton1 = True And Condition_TextBox <> "" _
'with other subs I have made default text in texbox which is shown until clicked
'this line should stop macro from starting if no text is entered and default text left
And Condition_TB <> "Enter Application ID" Then

' I want macro to loop throught all the table until it finds a match
For i = 3 To Range("Table1").Rows.Count

'Conditions to finding a match. Cell in column D should say "Remarks" and entered value should match cell in column A
If Condition_TB = Worksheets("sheet1").Cells(i, "A").Value _
And Worksheets("sheet1").Cells(i, "D").Value = "Remarks" Then
'If conditions are met I want macro to change column D cell value to "done" and write date from second texbox to cell in column N
Worksheets("sheet1").Cells(i, "N").Value = Condition_TB
Worksheets("sheet1").Cells(i, "D").Value = "Done"
'Since there will be no more mach I want to stop the loop
Exit For
End If
Next i

' Second option button similar to first, but it should not stop after first match
ElseIf OptionButton2 = True And Condition_TextBox <> "" _
And Condition_TB <> "Enter Application ID" _
And Condition_TB <> "Enter item number" Then

For i = 3 To Range("Table1").Rows.Count
If Condition_TB = Worksheets("sheet1").Cells(i, "P").Value _
And Worksheets("sheet1").Cells(i, "D").Value = "Make a call" Then
Worksheets("sheet1").Cells(i, "L").Value = DataTB
Worksheets("sheet1").Cells(i, "D").Value = "Call made"
End If
Next i
End If
End Sub

到目前为止,整个代码均未显示任何错误,但是单击并输入数据后,什么都没有发生。
由于我是初学者,所以整个代码本质上可能是错误的,请帮助我发现错误或进入正确的轨道。

最佳答案

我认为您在这一方面非常接近!

我要注意的头几件事可能是造成问题的原因是您的IF条件。

尝试这些更改,以查看是否获得所需的结果:

更改:

If OptionButton1 = True And Condition_TextBox <> "" Then


If OptionButton1 = True And Condition_TextBox.value <> "" Then

用户为用户窗体对象输入值的任何位置,并且您要检查用户定义输入的值,请在对象后添加“.value”以检查用户输入。

请记住,您的optionsbutton很好。当检查True或False时,这些选项按钮不需要“.value”属性。

future 的调试技巧:

作为帮助您将来调试代码的补充说明,可以在if语句之后通知您是否满足条件的情况下添加触发器。如果触发器未显示,则说明问题出在哪里。

例如:

您可以在条件之后立即添加以下内容:
MsgBox("Condition 1 was met!")

要么
Debug.Print("Condition 1 was met!")

让我们来看看哪里可以找到您。如果您还有其他问题,我们很乐意为您提供帮助!

关于vba - VBA循环宏不显示任何错误,但启动后不显示任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52313026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com