i 是名稱的陣列串列。j 使用該串列作為選項卡名稱。我遇到的問題是,如果該單元格范圍中有一個空單元格 - 或者如果陣列串列中的名稱不存在,我將如何“跳過該名稱”(或空單元格)并轉到下一個環形?我認為它會在 j 下,但除了 if 陳述句之外,我不確定從哪里開始?不確定如何為此撰寫 if 陳述句?
Set Tail = New ArrayList
Dim NewestEntry As Integer
Dim Apple As String
For i = 0 To 20 Step 3 'Tail #/Number of Tails
Apple = Worksheets("StepBrief").Cells(i 6, 3).Value
Tail.Add Apple
Next i
For j = 0 To 20 'Number of Tail # Cells
NewestEntry = Worksheets(Tail(j)).Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
uj5u.com熱心網友回復:
跳過空白和現有值ArrayList
- 在Excel MacroMastery 的網頁上了解 ArrayList 。
Option Explicit
Sub TestArrayList()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim ws As Worksheet: Set ws = wb.Worksheets("StepBrief")
Dim Tail As ArrayList: Set Tail = New ArrayList ' (early binding)
' If you don't want to create a reference to 'mscorlib.dll' since
' at this moment the array list's intelli-sense doesn't work anyway,
' instead, you could use (late binding):
'Dim Tail As Object: Set Tail = CreateObject("System.Collections.ArrayList")
Dim Apple As String
Dim i As Long
For i = 6 To 26 Step 3
Apple = CStr(ws.Cells(i, "C").Value)
If Len(Apple) > 0 Then ' is not blank
If Not Tail.Contains(Apple) Then ' is not already in array list
Tail.Add Apple
'Else ' already in array list; do nothing
End If
'Else ' is blank; do nothing
End If
Next i
' Some examples of what to do with it:
' Print the contents of 'Tail'.
Dim Item As Variant
For Each Item In Tail
Debug.Print Item
Next Item
' Write the values from 'Tail' to an array.
Dim Arr As Variant: Arr = Tail.ToArray
' Print the contents of the array.
For i = 0 To UBound(Arr)
Debug.Print i, Arr(i)
Next i
' Print the contents of the array as a comma-separated list using 'Join'
' (since the elements are strings).
Debug.Print Join(Arr, ",")
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491060.html
