1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| Option Explicit
Private mListObject As ListObject
Private mIndex As String
Private mName As String
Private Const VERSION As String = "2.0"
Function Init(Name As String, Optional Index As String, Optional wb As Workbook) As Long
InitListObject Name, wb
If mListObject Is Nothing Then
Init = 1
Else
mIndex = Index
End If
End Function
Private Sub InitListObject(Name As String, Optional wb As Workbook)
Dim sh As Worksheet
Dim lo As ListObject
Dim shCounter As Long, loCounter As Long
shCounter = 1
If wb Is Nothing Then Set wb = ThisWorkbook
Do While shCounter <= wb.Worksheets.Count And mListObject Is Nothing
loCounter = 1
Do While loCounter <= wb.Worksheets(shCounter).ListObjects.Count And mListObject Is Nothing
If StrComp(wb.Worksheets(shCounter).ListObjects(loCounter).Name, Name, vbTextCompare) = 0 Then Set mListObject = wb.Worksheets(shCounter).ListObjects(loCounter)
loCounter = loCounter + 1
Loop
shCounter = shCounter + 1
Loop
End Sub
Sub ShowAllData()
mListObject.AutoFilter.ShowAllData
End Sub
Property Get DataRange() As Range
Set DataRange = mListObject.DataBodyRange
End Property
Property Get ColumnExists(Name As String) As Boolean
Dim Counter As Long
Counter = 1
Do While Counter <= mListObject.ListColumns.Count And ColumnExists = False
If StrComp(mListObject.ListColumns(Counter).Name, Name, vbTextCompare) = 0 Then ColumnExists = True
Counter = Counter + 1
Loop
End Property
Property Get Index() As String
Index = mIndex
End Property
Property Get Table() As ListObject
Set Table = mListObject
End Property
Property Get Column(ByVal Name As String) As ListColumn
Set Column = mListObject.ListColumns(Name)
End Property
Property Get ColumnFromIndex(ByVal Index As Long) As ListColumn
Set ColumnFromIndex = mListObject.ListColumns(Index)
End Property
Property Get IsEmpty() As Boolean
IsEmpty = (mListObject.ListRows.Count = 0)
End Property
Property Get NewRow() As xlRow
Set NewRow = New xlRow
NewRow.Init mListObject.ListRows.Add()
End Property
Property Get Row(ByVal Value As Variant, Optional ByVal ColumnName As String) As xlRow
Dim Formula As String
Dim Pos As Variant
If ColumnName = "" Then ColumnName = mIndex
Select Case TypeName(Value)
Case "String"
Value = """" & Value & """"
End Select
If ColumnName <> "" Then
Formula = "match(" & Value & "," & mListObject.Name & "[" & ColumnName & "],0)"
Pos = Evaluate(Formula)
If Not IsError(Pos) Then
Set Row = New xlRow
Row.Init mListObject.ListRows(Pos)
End If
End If
End Property
Property Get RowFromIndex(Index As Long) As xlRow
If Index <= mListObject.ListRows.Count Then
Set RowFromIndex = New xlRow
RowFromIndex.Init mListObject.ListRows(Index)
End If
End Property
Property Get Name() As String
Name = mListObject.Name
End Property
Property Get RowsCount() As Long
RowsCount = mListObject.ListRows.Count
End Property
Public Function RowExists(Value As Variant) As Boolean
RowExists = Not Row(Value) Is Nothing
End Function |
Partager