(no)> 0 Then
no = Trim (no)
counter = count (street, no)
MsgBox "Кількість телефонів в будинку '" + street + "" + no + "':" + Str (counter)
End If
End If
End If
End If
reportForm.Hide
End Sub
Private Function count (Optional street, Optional no) As Long
Dim myRecord As Record
Dim data As Range, curRow As Range
Dim doCalc As Boolean, counter As Long
counter = 0
Range ("A5"). Activate
Set data = ActiveCell.CurrentRegion
For Each curRow In data.Rows
myRecord = getRecord (curRow)
doCalc = False
If IsMissing (street) Then
' всі абоненти
doCalc = True
Else
If IsMissing (no) Then
' по вулиці
doCalc = (Trim (myRecord.street) = street)
Else
' по дому
doCalc = (Trim (myRecord.street) = street) And (Trim (myRecord.no) = no)
End If
End If
If doCalc Then counter = counter + 1
Next curRow
count = counter
End Function
h2> sortForm
Private Sub UserForm_Activate ()
OKButton.SetFocus
End Sub
Private Sub CancelButton_Click ()
sortForm.Hide
End Sub
Private Sub OKButton_Click ()
Dim sht As Worksheet
Dim rng As Range
Set sht = ThisWorkbook.ActiveSheet
Set rng = sht.Range (sht.Cells (5, 1), sht.Cells (65536, 1). End (xlUp). Offset (, 7))
If NameOption.Value Then
' сортувати по ПІБ
rng.sort Key1: = sht.Columns ("A"), Order1: = xlAscending, Key2: = sht.Columns ("B"), Order2: = xlAscending, Key3: = sht.Columns ("C"), Order3: = xlAscending, Header: = xlNo
Else
If AddressOption.Value Then
' сортувати по адресою
rng.sort Key1: = sht.Columns ("D"), Order1: = xlAscending, Key2: = sht.Columns ("E"), Order2: = xlAscending, Key3: = sht.Columns ("F"), Order3: = xlAscending, Header: = xlNo
Else
' сортувати по телефону
rng.sort Key1: = sht.Columns ("G"), Order1: = xlAscending, Header: = xlNo
End If
End If
sortForm.Hide
End Sub
h2> Module1
Public Type Record
Fam As String
Im As String
Ot As String
street As String
no As String
Flat As String
Phone As Long
End Type
Public Function dbFileName () As String
dbFileName = ThisWorkbook.Path + " phones.db"
End Function
Sub ToolbarExitButton ()
If ThisWorkbook.ActiveSheet.Name = "Старт" Then
ExitProject
Else
ThisWorkbook.Worksheets ("Старт"). Visible = True ' заховати стартовий лист
ThisWorkbook.Worksheets ("Старт"). Activate ' зробити активним лист з БД
ThisW...