Excel vba - 如何在单元格中找到第 8 位数字并评估它是否正确

标签 excel vba

到目前为止得到了这个vba:

For Each cell In Range("A2", Range("A" & Rows.Count).End(xlUp))
If Len(cell.Value) = 11 Then
cell.Copy Destination:=Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next cell

我需要在第二行的“11”后面添加一些代码,但我不知道怎么写。我想要做的是添加类似“and digit number 8 (of 11) is 1 or 3 or 5 or 7 or 9 then”的东西。
任何人都可以帮助我吗?

最佳答案

尝试这个

For Each cell In Range("A2", Range("A" & Rows.Count).End(xlUp))
    If Len(cell.Value) = 11 Then
        Select Case Mid(cell.Value, 8, 1)
        Case 1, 3, 5, 7, 9
             cell.Copy Destination:=Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
        End Select
    End If
Next cell

关于Excel vba - 如何在单元格中找到第 8 位数字并评估它是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50618887/

相关文章:

excel - 使用 Excel 2010 通过存储过程读取/写入 SQL Server 2008 数据库

excel - 网页抓取 - 更改变量

excel - 在 countifs 中指定可变长度公式

c# - Excel 公式和元数据

excel - 使用 Excel VBA 宏捕获并保存同一文件中特定区域的屏幕截图

excel - Excel的 'Dependency-Chain'是增加还是减少?

excel - 为什么单击 Excel/Word 中的链接似乎会导致我的非 IE 浏览器伪装成 MSIE 7.0?

html - 如何为电子邮件格式化 html 表格

vba - 无法使用 xhr 从网页中获取一些信息

excel - 修复我的宏以将范围复制到下一个空白列?