作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Set ws1 = wb.Worksheets("MacroGeneratedReport")
LastRow = ws1.Cells(Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1
If ws1.Cells(i, "I").Value = "A" Or ws1.Cells(i, "I").Value = "B" Or
ws1.Cells(i, "I").Value = "C" Or ws1.Cells(i, "I").Value = "D" Or
ws1.Cells(i, "I").Value = "E" Or ws1.Cells(i, "I").Value = "F" Or
ws1.Cells(i, "I").Value = "Y" Then
ws1.Cells(i, "AO").Value = ws1.Cells(i, "Y").Value
Else
**ws1.Cells(i, "AO").Value = ws1.Cells(i, "AP").Value * ws1.Cells(i, "W").Value**
End If
Next i
最佳答案
您的代码“尖叫”使用Select Case
而不是你的多个 Or
s。
代码
Set ws1 = wb.Worksheets("MacroGeneratedReport")
With ws1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1
Select Case .Cells(i, "I").Value
Case "A", "B", "C", "D", "E", "F", "Y"
.Cells(i, "AO").Value = .Cells(i, "Y").Value
Case Else
' check that both values are numeric
If IsNumeric(.Cells(i, "AP").Value) And IsNumeric(.Cells(i, "W").Value) Then
.Cells(i, "AO").Value = .Cells(i, "AP").Value * .Cells(i, "W").Value
End If
End Select
Next i
End With
关于If Else 条件下的 Vba 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47881881/
我是一名优秀的程序员,十分优秀!