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 - 2)) + ":" + Trim(Str(oGrHeader.Row - 1))).Copy
                sr.Offset(1, 0).Insert Shift:=xlDown
                Application.CutCopyMode = False
                wsh.Cells((groupCount - 3) * 3 + 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
                If (sr.Offset(2, 1).Value = "0000") And IsUpGroup("podraz") Then
                    sr.Offset(2, 1).Value = ">>ТЕКСТ({podraz};""0000"")"
                End If
                If (sr.Offset(2, 2).Value = "000") And IsUpGroup("glava") Then
                    sr.Offset(2, 2).Value = ">>ТЕКСТ({glava};""000"")"
                End If
                If (sr.Offset(2, 3).Value = "000") And IsUpGroup("c_st") Then
                    sr.Offset(2, 3).Value = ">>ТЕКСТ({c_st};""000"")"
                End If
                If (sr.Offset(2, 4).Value = "000") And IsUpGroup("rash") Then
                    sr.Offset(2, 4).Value = ">>ТЕКСТ({rash};""000"")"
                End If
                If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st6") Then
                    sr.Offset(2, 5).Value = ">>ТЕКСТ({st6};""000000"")"
                Else
                    If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st5") Then
                        sr.Offset(2, 5).Value = ">>ТЕКСТ({st5};""000000"")"
                    Else
                        If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st4") Then
                            sr.Offset(2, 5).Value = ">>ТЕКСТ({st4};""000000"")"
                        Else
                            If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st3") Then
                                sr.Offset(2, 5).Value = ">>ТЕКСТ({st3};""000000"")"
                            Else
                                If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st2") Then
                                    sr.Offset(2, 5).Value = ">>ТЕКСТ({st2};""000000"")"
                                Else
                                    If (sr.Offset(2, 5).Value = "000000") And IsUpGroup("st1") Then
                                        sr.Offset(2, 5).Value = ">>ТЕКСТ({st1};""000000"")"
                                    Else
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            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

