excel - VBA - 不确定我的 if 语句中的错误在哪里(有多个条件)
问题描述
我不确定为什么我总是得到其他条件,而不是另一个。我不确定我的双重 if 条件语法是否错误。如果有人可以验证/知道出了什么问题,那就太好了。
基本上,如果该单元格中的值是 4 位数字并且第一个字母是 F,则不需要错误消息。
RowCount = Cells(Rows.Count, "C").End(xlUp).Row
For i = 2 To RowCount
If Len(Cells(i, 4).Value) = 4 And Left(Cells(i, 4), 1) = "F" Then
'Do nothing, no IA Code errors
MsgBox "no errors"
Else
MsgBox "Error, please resubmit"
Exit Sub
End If
Next i
解决方案
我只在第 2 行将“C”更改为 4。看起来您指的是错误的列来分配 RowCount。
Sub Error_NoError()
RowCount = Cells(Rows.Count, 4).End(xlUp).Row
For i = 2 To RowCount
If Len(Cells(i, 4).Value) = 4 And Left(Cells(i, 4), 1) = "F" Then
'Do nothing, no IA Code errors
MsgBox "no errors"
Else
MsgBox "Error, please resubmit"
Exit Sub
End If
Next i
End Sub
推荐阅读
- php - Nginx + PHP-FPM:PHP-FPM 容器的 5000 端口连接被拒绝,而 9000 端口没有问题
- python - 如何在 Django 中进行分层验证?
- python - 在python中动态更改嵌套字典的值
- javascript - 在 chrome 上使用 requestAnimationFrame 每 100 毫秒调用一个函数
- python - 为什么我会收到错误消息“start_time is not defined”?
- python-3.x - 如何使用 numpy 从多个数组中获取相同索引的值?
- angular - 将具有 svg 文件的 Angular 组件选择器作为 templateUrl 从主路由组件动态传递到其他共享的 Angular 组件,而无需 *ngIf
- python - 如果在另一列中包含字符串,则在其中一列中返回“是”
- javascript - 是否有任何合适的 API 可以编写 chrome 扩展来下载 cookie 身份验证后的图像?
- r - 从闪亮的 Web 应用程序将 csv 或 xslx 文件写入光盘