简体   繁体   English

Range.offset 属性

[英]Range.offset propety

I'm trying to understand a code on VBA, to debug the VBA program of someone.我试图了解 VBA 上的代码,以调试某人的 VBA 程序。 So I want to know that is the property and the meaning of Range (Value).offset(x;y).所以我想知道Range(Value).offset(x;y)的属性和含义。 Here is my code:这是我的代码:

`Sub initialise()
Dim i As Double, j As Double
For i = 0 To maxnodes - 1
For j = 0 To 1
    **If Range(initial_range).Offset(i, j) <> 0 Then**
       Range(Startrange).Offset(i, j) = Range(initial_range).Offset(i, j)
    Else
       Range(Startrange).Offset(i, j) = Empty
    End If
Next j
Next i

End Sub`

Can you help me please?你能帮我吗? If you need more details, don't exist如果您需要更多详细信息,请不要存在

The .Offset property is used to move a certain position from a specified location. .Offset属性用于从指定位置移动某个位置。

It is used like:它的用法如下:

ActiveSheet.Cells(1, 1).Offset(Row, Column)

Where positive values move the position down (by the stated amount) for the Row value, and to the right (by the stated amount) for the column value.正值将位置向下移动(按规定数量)行值,向右移动(按规定数量)列值。 Negative values move in the opposite way.负值以相反的方式移动。

Therefore, something like ActiveSheet.Cells(1,1).Offset(2, 0) (Where ActiveSheet.Cells(1,1) represents cell A1 ) Would actually be referring to cells(3, 1) or A3 .因此,类似于ActiveSheet.Cells(1,1).Offset(2, 0) (其中ActiveSheet.Cells(1,1)代表单元格A1 )实际上是指cells(3, 1)A3

Therefore, in your code using the for loop and the offset property;因此,在您的代码中使用 for 循环和 offset 属性; the code is creating a new matrix using all the values that aren't equal to 0. (also you will need to remove the ** to get it to run)代码正在使用所有不等于 0 的值创建一个新矩阵。(您还需要删除**以使其运行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM