[VBA]判斷式的應用及參考
x
1r = 1
2re = Cells(ActiveSheet.Rows.Count, 2).End(xlUp).Row
3rs = 9
4
5For r = rs To re
6'or 的判斷需要將條件寫完整,不能省略等號左邊的條件
7 If Cells(r, 7).Value = "新增項目新單價" Or Cells(r, 7).Value = "需議價" Then
8'Range的變數要用下列方式呈現
9 Range("E" & r & ":F" & r).Select
10 Selection.ClearContents
11'elseif 跟 and 的格式直接寫就好
12 ElseIf Cells(r + 1, 3).Value = "" And Cells(r + 1, 7).Value = "新增項目新單價" Then
13 Range("E" & r & ":F" & r).Select
14 Selection.ClearContents
15 ElseIf Cells(r, 2).Value = "合計" Then
16 Range("F" & r).Select
17 Selection.ClearContents
18'like 可以寫成判斷式。如Cells(r, 4) Like "*單價計*" = true then 這樣
19 ElseIf Cells(r, 4) Like "*單價計*" Then
20 Range("F" & r).Select
21 Selection.ClearContents
22 End If
23Next
沒有留言:
張貼留言