我想了解excel vba中两个点的用法是什么。
Sub loadparts(a)
Sheets("Sheet1").Select
Dim lists()
b = 2
'what is the meaning of two dots.
x:
If Cells(b, a) <> "" Then
ReDim Preserve lists(1 To b - 1)
lists(b - 1) = Sheets(b, a)
b = b - 1: GoTo x
End If
UserForm1.ListBox1.List = lists()
End Sub
Run Code Online (Sandbox Code Playgroud)
这两个点称为冒号。冒号在 Visual Basic for Applications 中有两个函数
定义标签:在您的示例中x是一个标签。您可以使用标签通过语句跳转到代码的特定部分goto。在您的示例中,这发生在这一行:
b = b - 1: GoTo x
Run Code Online (Sandbox Code Playgroud)
您可以使用它来分隔指令(这偶然发生在同一行)。在 VBA 中,我们通常用换行符分隔语句,但也可以使用冒号。尽管这通常读起来不太容易。再次抓取同一行代码:
b = b - 1: GoTo x
is equivalent to
b = b - 1
GoTo x
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3012 次 |
| 最近记录: |