我有一个工作表,其中 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/