遍历范围但使用 nxt col 作为值
loop through a range but use the nxt col as value
我有一个 excel 代码查看范围 A1:A100...它循环遍历这些范围,但是当它循环时,我想选择 col B 中的值...对于例如,当范围循环开始时,它会首先查看 A1,但在 VBA 中,我希望它选择 B1 中的值来使用...
Sub DRAWb()
'
' DRAWb Macro
'
'
Dim rng As Range, cell As Range
Set rng = Sheet1.Range("A1:A3")
For Each cell In rng
If cell.Value > 1 Then
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 11.25, 50 * cell, 93.75, 43.5) _
.Name = "R cell"
End If
Next cell
End Sub
使用.Offset
方法,"Returns a Range object that represents a range that’s offset from the specified range."
If cell.Offset(0, 1).Value > 1 Then
上面的计算结果为 下一个 列。
文档:
http://msdn.microsoft.com/en-us/library/office/ff840060%28v=office.15%29.aspx
我有一个 excel 代码查看范围 A1:A100...它循环遍历这些范围,但是当它循环时,我想选择 col B 中的值...对于例如,当范围循环开始时,它会首先查看 A1,但在 VBA 中,我希望它选择 B1 中的值来使用...
Sub DRAWb()
'
' DRAWb Macro
'
'
Dim rng As Range, cell As Range
Set rng = Sheet1.Range("A1:A3")
For Each cell In rng
If cell.Value > 1 Then
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 11.25, 50 * cell, 93.75, 43.5) _
.Name = "R cell"
End If
Next cell
End Sub
使用.Offset
方法,"Returns a Range object that represents a range that’s offset from the specified range."
If cell.Offset(0, 1).Value > 1 Then
上面的计算结果为 下一个 列。
文档:
http://msdn.microsoft.com/en-us/library/office/ff840060%28v=office.15%29.aspx