VBA编程:缩进、字符串与对象操作全解析
1. 代码缩进的重要性与操作方法
让程序更具可读性,除了添加注释,严格进行代码缩进是非常有效的方法。以下是两个功能完全相同的子程序示例,对比缩进与不缩进的代码,你会明显感觉到缩进后的代码更易于阅读。
缩进正确的版本 :
Sub CountHighSales()
Dim i As Integer
Dim j As Integer
Dim nHigh As Integer
Dim cutoff As Currency
cutoff = InputBox("What sales value do you want to check for?")
For j = 1 To 6
nHigh = 0
For i = 1 To 36
If wsData.Range("Sales").Cells(i, j) >= cutoff Then _
nHigh = nHigh + 1
Next i
MsgBox "For region " & j & ", sales were above " & Format(cutoff, "$0,000") _
& " on " & nHigh & " of the 36 months."
Next j
End Sub
未缩进
超级会员免费看
订阅专栏 解锁全文
67

被折叠的 条评论
为什么被折叠?



