vba - 移动到下一行重复过程vba

标签 vba excel

我有一个工作表,其中 A 列列出了一系列风险。

F 列列出了可以减轻这些风险的项目。
我想编写一个脚本来确定风险是否有控制或没有控制
例如

A                  F
Risk7              control
                   monitor
                   test
Risk8              (blank)

所以输出将是 1 个有控制的风险和一个没有控制的风险

到目前为止我的脚本是
Sub CountWithWithoutControls()

' counts number of risks with controls and without controls, 
' currently running through each cell and comparing back to original control, 
' need to write to get it to walk down the series

 Dim cell As Range
 Dim myrange As Range
 Dim control As Long
 Dim WoControl As Long

 Set myrange = Range("a7:f27")

 For Each cell In myrange     
     If Range("c7") <> "" And Range("f7") = "Control" Then control = control + 1
     If Range("c7") <> "" And Range("f7") <> "Control" Then WoControl = WoControl + 1     
 Next cell

 MsgBox control & "  = number of risks with controls" & WoControl & ("  = number of risks without controls")

 End Sub

我是 VBA 的新手,虽然我认为这不应该那么难,但我没有取得任何进展。任何正确方向的提示将不胜感激!
谢谢你们
保罗

最佳答案

我建议这个更正

 For Each cell In range("F7:F27")
     if cell.offset(,-3)<>"" then ' check if cell in column C is not empty 
        if cell = "Control" then control=control+1 else WoControl=WoControl+1   
     end if
 Next cell

关于vba - 移动到下一行重复过程vba,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39354550/

相关文章:

vba - #value 错误,但在 VBA 中有效

excel - 不同工作表(同一单元格)中的值求和

vba - 在 Excel 中通过 VBA 编辑自定义样式

javascript - 将数据从大容量 csv 过滤到小 csv

excel - 比较 2 列并删除重复项而不移动

vba - 选择其他工作表或工作簿时尝试使用 ThisWorkbook 设置范围值时出现问题

excel - Personal.xlsb 文件中的用户定义函数挂起 Excel。有没有办法避免这种情况并优化执行?

excel - VBA:对矩阵求和

c# - 使用互操作和 C# 计算 Excel 电子表格工作表中的行数,其中数据为

mysql - 将复杂数据从csv导入到mysql表