excel - 如何在 Excel 中跨列处理多个 IFTHEN 查询?

标签 excel vba

我正在尝试创建一个分配系统,虽然我已经编程了 VBA在我被卡住之前!

我有五列数据,其中的内容决定了我分配给他们的工作人员。

我需要做的是:

If column E = "a", then put name "xx" in column A (of same row)
If column E = "b", then put name "yy" in column A (of same row)
If column E is blank, then move to next criteria....

If column D is "c" then put name "zz" in column A (of same row)
If column D is "d" then move to next criteria....

If column A is blank then put name "ww" in column A.

提前致谢!!

最佳答案

Sub Allocate()

    Dim i As Long

    For i = 1 To Range("E" & Rows.Count).End(xlUp).Row
        If Range("E" & i) = "a" Then
            Range("A" & i) = "xx"
        ElseIf Range("E" & i) = "b" Then
            Range("A" & i) = "yy"
        End If

        If Range("D" & i) = "c" Then
            Range("A" & i) = "zz"
        End If

        If IsEmpty(Range("A" & i)) Then
            Range("A" & i) = "ww"
        End If
    Next i

End Sub

注意
If column E is blank, then move to next criteria....
没有包含在代码的任何地方,没有必要在代码中实现它,因为它确实是 什么都没有 :)

关于excel - 如何在 Excel 中跨列处理多个 IFTHEN 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19833679/

相关文章:

html - VBA 数据从 Google 导入 Excel : Custom Time Ranges

excel - 用大写字母改变单词的颜色

excel - 用于比较两列并用颜色突出显示单元格差异的 VBA 宏

excel - "Automation Error: Object Invoked has disconnected from its clients"

vba - 删除和添加Excel表中的项目VBA

r - 使用R在Excel工作表中创建图表

vba - 在 VBA 中将列表框作为函数参数传递给我一个运行时错误 13

vba - 将不同工作表中的列复制到 VBA 中具有 1 个固定列的主工作表中

excel - 将源工作表复制到源工作表名称更改的另一个工作簿

python - 使用 Python Loop 从 Excel 文件创建多个 .txt 文件