|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
如题,IF函数是否可以作为多条件IF函数本身的条件成立结果?
下面是部分代码,有没有路过的帮忙分析注释下,这么多个if应该怎么看? 底子较薄,嵌套一多就晕了。谢谢了。
- Dim WireData() As String
- Private Sub SortPart() 'store page to arrar
- ReadPage (Cells(6, 2).Value)
- Dim intVariable As Integer
- Dim ComTERM As Boolean
- Dim ComTERM01 As Boolean
- Dim ComTERM02 As Boolean
- Dim ComCABLE As Boolean
- Dim CheckCableLength As Boolean
- ThisWorkbook.Worksheets("Report").Range("A3:N300").ClearContents
- ThisWorkbook.Worksheets("DT").Range("K2:K300").ClearContents
- ThisWorkbook.Worksheets("DT").Range("T2:T300").ClearContents
- CheckCableLength = False
- For n = 1 To UBound(WireData, 2)
-
- ComCABLE = False
- ComTERM = False
- ComTERM01 = False
- ComTERM02 = False
-
- For h = 2 To ThisWorkbook.Worksheets("DT").UsedRange.Rows.Count
- 'sort the connectors which HPN in LABEL column
- If WireData(2, n) = "CNCTR" Then
-
- If WireData(5, n) = "" Then
-
- If WireData(2, n) & WireData(6, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Then
- Worksheets("DT").Cells(h, 11).Value = Worksheets("DT").Cells(h, 11).Value + 1
- WireData(6, n) = Worksheets("DT").Cells(h, 8).Value
- ComTERM = True
- End If
-
- Else:
-
- If WireData(2, n) & WireData(5, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Then
- Worksheets("DT").Cells(h, 11).Value = Worksheets("DT").Cells(h, 11).Value + 1
- WireData(5, n) = Worksheets("DT").Cells(h, 8).Value
- ComTERM = True
- End If
- End If
- Else:
-
- If WireData(2, n) & WireData(5, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Or WireData(5, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Then
- Worksheets("DT").Cells(h, 11).Value = Worksheets("DT").Cells(h, 11).Value + 1 'statistic terminal
- WireData(5, n) = Worksheets("DT").Cells(h, 8).Value 'replace termianl type
- ComTERM01 = True
- End If
-
- If WireData(2, n) & WireData(7, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Or WireData(7, n) = Worksheets("DT").Cells(h, 6).Value And Worksheets("DT").Cells(h, 6).Value <> "" Then
- Worksheets("DT").Cells(h, 11).Value = Worksheets("DT").Cells(h, 11).Value + 1 'statistic terminal
- WireData(7, n) = Worksheets("DT").Cells(h, 8).Value 'replace termianl type
- ComTERM02 = True
- End If
-
- ComTERM = ComTERM01 And ComTERM02
-
- If WireData(2, n) & WireData(3, n) = Worksheets("DT").Cells(h, 15).Value And Worksheets("DT").Cells(h, 15).Value <> "" Then
- ComCABLE = True
-
- If WireData(4, n) <> "" And WireData(4, n) <> " " And WireData(4, n) <> "N/A" And WireData(4, n) <> "TBD" Then
- intVariable = Val(WireData(4, n)) / 100
-
- If 0 < intVariable Then Worksheets("DT").Cells(h, 20).Value = Worksheets("DT").Cells(h, 20).Value + intVariable
-
- Else: CheckCableLength = True
- ' WireData(1, n) = "无长度"pirate
- End If
-
- End If
-
- End If
-
- Next h
-
-
- For j = 1 To UBound(WireData, 2)
- x = x + 1
- If WireData(10, j) <> WireData(10, j - 1) Then '工作表名不相等时,一段范围内同一工作表
- Worksheets.Add before:=Worksheets("sheet1")
- TotallPage = TotallPage + 1
- x = 1
- ActiveSheet.Name = WireData(10, j)
- End If
-
- For i = 1 To 9
- ActiveSheet.Cells(x, i).Select
- If (i = 2 Or i = 6 Or i = 8) And WireData(i, j) <> "" Then
- ActiveCell.FormulaR1C1 = "'" & WireData(i, j)
- Else: ActiveSheet.Cells(x, i).Value = WireData(i, j)
- 'ActiveCell.FormulaR1C1 = "'4/0"
- End If
- Next i
- Next j
-
- End Sub
复制代码
|
|