【发布时间】:2018-09-10 10:52:56
【问题描述】:
我正在编写一段代码,该代码循环遍历列中的所有值(直到它到达空行)并将包含“Wooden”的值添加到要在消息框末尾显示的范围内。
在链接Here 的图像中,它将从 A2 开始并向下每一行,检查 C 列中该过山车的值,如果 C 是木制的,则将 A 中的值添加到要显示的范围结束。
代码:
Sub checktype()
Dim wooden As Range
Range("A2").Select
Do While ActiveCell.Value <> ""
If ActiveCell.Offset(0, 2).Value = "Wood" Then
If wooden Is Nothing Then
Set wooden = ActiveCell
Else
Set wooden = Union(wooden, ActiveCell)
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
MsgBox wooden
End Sub
但是,代码只返回“Grand National”——C 列中第一个有木头的条目。
【问题讨论】:
标签: vba