excel - 如何在 VBA excel 中的 If 语句中使用组合框值?
问题描述
我需要在 Excel 中更新 VBA 上现有的票号
但是,我多次尝试将数据从工作表带到票号的组合框,从“A2”到 lastRow 添加,但它告诉我它的语法错误。
如何取 ComboBox 的值?如何将其插入到 IF 语句中?请帮我做以下条件
- 从门票表中获取门票号码
- 将combBox Close by和Ticket Status中的更新值写入两个Ticket Sheet,如果Ticket 状态为Solved 或Closed,则将它们从PendingTickets表中删除
测试工单状态是否为待处理或进行中的代码
Dim Ws As Worksheet
Dim lastRow As Long
Dim openOn As Date
'Declare openBy to date Now function'
openOn = Now()
'set format function on time var'
openTimeAmPM = Format(openOn, "m.d.yy h:mm AM/PM")
'copy ticket data to Pending tickst sheet if the ticket status is Pending or On progress'
' If SieraForum.CombTicketStatus.Value = "Pending" Or "On Progress" Then
Sheets("PendingTickets").Cells(lastRow + 1, 1).Value = lastRow
Sheets("PendingTickets").Cells(lastRow + 1, 2).Value = SieraForum.txtTicketName.Value
ElseIf SieraForum.ErrorOption = True Then
Sheets("PendingTickets").Cells(lastRow + 1, 3).Value = "Error"
ElseIf SieraForum.OrderOption = True Then
Sheets("PendingTickets").Cells(lastRow + 1, 3).Value = "Order"
Sheets("PendingTickets").Cells(lastRow + 1, 4).Value = SieraForum.CombSeverity.Value
Sheets("PendingTickets").Cells(lastRow + 1, 5).Value = SieraForum.CombLocation.Value
Sheets("PendingTickets").Cells(lastRow + 1, 6).Value = SieraForum.txtTicketDetails.Value
Sheets("PendingTickets").Cells(lastRow + 1, 7).Value = SieraForum.CombOpenBy.Value
Sheets("PendingTickets").Cells(lastRow + 1, 8).Value = SieraForum.CombCloseBy.Value
Sheets("PendingTickets").Cells(lastRow + 1, 9).Value = SieraForum.CombTicketStatus.Value
Sheets("PendingTickets").Cells(lastRow + 1, 10).Value = openTimeAmPM
Else
MsgBox "The Ticket is Added Successfully"
End If
点击更新票证上的保存按钮代码
Private Sub btnSave2_Click()
'declare close on date function'
Dim closeOn As Date
' set format function on time var'
closeOn = Now()
closeTimeAmPM = Format(openOn, "m.d.yy h:mm AM/PM")
'To enter new line'
lastRow = WorksheetFunction.CountA(Sheets("Tickets").Range("A:A"))
Sheets("Tickets").Cells(lastRow + 1, 1).Value = lastRow
Sheets("Tickets").Cells(lastRow + 1, 8).Value = SieraForum.CombCloseBy.Value
Sheets("Tickets").Cells(lastRow + 1, 9).Value = SieraForum.CombTicketStatus2.Value
'write the update statement'
'Sheets("Tickets").Cells(lastRow + 1, 12).Value = "Update Statement > " + SieraForum.txtTicketUpdate.Value
Sheets("Tickets").Cells(lastRow + 1, 11).Value = closeTimeAmPM
'Clear the data from the form'
SieraForum.CombTicketNum.Value = ""
SieraForum.CombCloseBy = ""
SieraForum.CombTicketStatus2 = ""
SieraForum.txtTicketUpdate.Value = ""
End Sub
解决方案
第一个If
被注释掉。语法错误是由有和ElseIf
没有匹配引起的。Else
End If
If
推荐阅读
- reactjs - Grommet DataTable 仅允许单选
- mysql - 如何使用 select 语句的结果作为列名?
- reactjs - 如何使用 BrowserRouter 和 Switch 的路由数组映射而不同时加载它们?
- android - 我在 M1 mac 上运行 android 模拟器时遇到问题
- algolia - 如何使用 Instantsearch 生成 SEO URL
- android - Jetpack compose 中的 ClickableText 样式
- python - 当使用像 Uvicorn 这样的 ASGI 服务器时,Flask 记录器不起作用
- .net - 如何正确使用 DataAnnotations 在 .NET 5.0 中使用 Identity 注册用户?
- web-services - 我如何从 Prestashop WebService 运行课程
- r - 仅当环境中存在变量时,如何在 R 中运行块?否则跳到下一个块