Attribute VB_Name = "Модуль4"
Option Explicit

Sub AddGroup2(lcField As String)
Dim sr As Range, oGrHeader As Range
        groupCount = groupCount + 1
        groupProp(groupCount, 1) = lcField
        Set sr = wso.Cells.Find("^ Шапка группы №" + Trim(Str(groupCount - 1)) + ":", LookIn:=xlValues)
        If sr Is Nothing Then
            MsgBox ("Нет шапки предыдущей группы!")
        Else
            sr.Offset(1, 0).EntireRow.Insert
            wso.Rows(sr.Offset(1, 0).Row).Interior.ColorIndex = 15
            sr.Offset(1, 0).Value = "^ Шапка группы №" + Trim(Str(groupCount)) + ":"
            sr.Offset(1, 1).Value = lcField
            sr.Offset(1, 2).Value = False
            sr.Offset(1, 3).Value = False
            sr.Offset(1, 4).Value = True
            sr.Offset(1, 5).Value = False
            sr.Offset(1, 6).Value = False
            Set oGrHeader = wsh.Cells.Find("^" + lcField, LookIn:=xlValues)
            If Not (oGrHeader Is Nothing) Then
                wsh.Rows(Trim(Str(oGrHeader.Row - 1)) + ":" + Trim(Str(oGrHeader.Row - 1))).Copy
                sr.Offset(1, 0).Insert Shift:=xlDown
                Application.CutCopyMode = False
                wsh.Cells((groupCount - 3) * 2 + 1, 1).Copy
                sr.Offset(1, 0).PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
                    False, Transpose:=False
                sr.Offset(1, 0).Value = ">>""" + Space((groupCount - 3) * 2) + """ & " + Mid(sr.Offset(1, 0).Value, 3)
                Application.CutCopyMode = False
            End If
        End If
        Set sr = wso.Cells.Find("^ Данные")
        If sr Is Nothing Then
            MsgBox ("Нет области данных!")
        Else
            sr.Offset(1, 0).EntireRow.Insert
            wso.Rows(sr.Offset(1, 0).Row).Interior.ColorIndex = 15
            sr.Offset(1, 0).Value = "^ Концовка группы №" + Trim(Str(groupCount)) + ":"
            Set oGrHeader = wsh.Cells.Find("^Концовка", LookIn:=xlValues)
            If Not (oGrHeader Is Nothing) Then
                wsh.Rows(Trim(Str(oGrHeader.Row - 1)) + ":" + Trim(Str(oGrHeader.Row - 1))).Copy
                sr.Offset(1, 0).Insert Shift:=xlDown
            End If
        End If
End Sub

