我是vba的新手,我正在尝试创建一个模块,该模块采用C列中的值(应该说“正在进行中”),并且如果E列上同一行内的值为“中性”,则使其为“中性”。小于0.5(或50%),但我没有运气。我有一个计数器变量,用于跟踪我所在的行。任何建议都会有所帮助,如果你能推荐我学习vba的好资料,我会非常感激。
If Range("C1") = "Status" Then
Range("C1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Offset(1, 0).Value = "In Progress" Then
If Range("E" & counter).Value < 0.5 Then
ActiveCell.Offset(1, 0).Style = "Neutral"
End If
End If
ActiveCell.Offset(1, 0).Select
Columns("C").ColumnWidth = 13
counter = counter + 1
Loop
End If
End Sub
答案 0 :(得分:0)
未测试:
Dim c As Range, sht As WorkSheet
Set sht = ActiveSheet
If sht.Range("C1").Value = "Status" Then
Set c = sht.Range("C2")
Do Until Len(c.Value) = 0
If c.Value = "In Progress" Then
If c.EntireRow.Cells(1, "E").Value < 0.5 Then
c.Style = "Neutral"
Else
c.Style = "Normal"
End If
End If
Set c = c.Offset(1, 0)
Loop
sht.Columns("C").ColumnWidth = 13
End If
答案 1 :(得分:0)
据我了解你的问题,这适合你,你可以试试这个。以下代码在整个A列中搜索值“In Progress”,如果找到此值并且C列中的相同行单元格小于0.5,则将A列中单元格的颜色设置为“no fill”
Sub searchValue()
Dim cell As Range
For Each cell In Worksheets(1).Columns(1).Cells
If cell = "In Progress" Then
If cell.Offset(0, 2) < 0.5 Then cell.Interior.ColorIndex = 0
End If
Next cell
End Sub