Advertisement
falazure123

Untitled

Jan 17th, 2023
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub format_Sub_String(top As Integer, left As Integer, rows As Integer, columns As Integer)
  2. Dim str_copy As String, LT As Integer, RB As Integer, i As Integer
  3.  
  4. ' ÎÏÐÅÄÅËÈÒÜ ÔÎÐÌÀÒ ÏÎÑËÅÄÍÞÞ ÑÒÐÎÊÓ ÒÀÁËÈÖÛ
  5.  str_copy = str_range(top + 2, left, 1, columns)
  6.   Selection.Copy        ' ñêîïèðîâàòü
  7.  str_copy = str_range(top + rows - 1, left, 1, columns)
  8.   Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
  9.       SkipBlanks:=False, Transpose:=False
  10.   Application.CutCopyMode = False
  11.  
  12.  
  13. ' îïðåäåëÿåì äèàïàçîí ñòðîêè, ôîðìàò êîòîðîé êîïèðóþò
  14.  str_copy = str_range(top + 1, left, 1, columns)
  15.   Selection.Copy
  16. ' îïðåäåëÿåì äèàïàçîí ñòðîê, â êîòîðûé ôîðìàòèðóåì
  17.  str_copy = str_range(top + 2, left, rows - 3, columns)
  18.   Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
  19.       SkipBlanks:=False, Transpose:=False
  20.   Application.CutCopyMode = False
  21.  
  22. ' î÷èñòèòü ÿ÷åéêó ñïðàâà îò íàäïèñè "ÈÒÎÃ:"
  23.  str_copy = str_range(top + rows - 1, left + 1, 1, 1)
  24.   Selection.ClearContents
  25.   ActiveCell.Value = ""
  26.  
  27.   str_copy = str_range(top + rows + 3, left, 10, 2)
  28.   With Selection
  29.        .HorizontalAlignment = xlLeft
  30.        .Font.Bold = True
  31.   End With
  32.  
  33.  
  34.   For i = top To top + rows - 2
  35.     str_copy = str_range(i, left + 2, 1, 1)
  36. '   åñëè ÿ÷åéêà ïóñòàÿ, òî îòôîðìàòèðîâàòü ñòðîêó
  37.    If ActiveCell.Value = "" Then
  38.        str_copy = str_range(i, left, 1, columns)
  39. '      ñåðàÿ âíóòðåííîñòü
  40.       With Selection.Interior
  41.             .ColorIndex = 15
  42.             .Pattern = xlSolid
  43.        End With
  44.        Selection.Font.Bold = True  ' æèðíûé øðèôò
  45.    End If
  46.   Next i
  47.  
  48.  
  49.   str_copy = str_range(top, left, 1, 1)
  50. End Sub
  51.  
  52.  
  53. Function str_range(top As Integer, left As Integer, rows As Integer, columns As Integer) As String
  54.   LT = Asc("A") + left - 1     ' ASC êîä áóêâû ëåâîé êîëîíêè
  55.  RB = LT - 1 + columns ' ASC êîä áóêâû ïðàâîé êîëîíêè
  56. ' ÎÏÐÅÄÅËÈÒÜ ÔÎÐÌÀÒ ÏÎÑËÅÄÍÞÞ ÑÒÐÎÊÓ ÒÀÁËÈÖÛ
  57. ' îïðåäåëÿåì äèàïàçîí ñòðîêè, êîòîðóþ êîïèðóþò
  58.  str_copy = Trim$(Chr(LT)) & Trim$(Str(top)) & ":" & _
  59.              Trim$(Chr(RB)) & Trim$(Str(top + rows - 1))
  60.   range(Cells(top, left), Cells(top + rows - 1, left + columns - 1)).Select
  61.   ' Range(str_copy).Select
  62.  
  63.   str_range = str_copy
  64. End Function
  65.  
  66.  
  67. Sub PrepareRows(top As Long, lines As Long)
  68. Dim i As Long
  69. 'Dim top As Long
  70. Dim ch_top As String
  71. Dim add_lines As Long
  72. Dim ch_add_lines As String
  73. Dim range As String
  74. Dim ostatok As Long
  75. Dim c4ak As Long
  76. Dim all As Long
  77.     ActiveWindow.WindowState = xlMaximized
  78.     Application.WindowState = xlMaximized
  79.     Application.CutCopyMode = False
  80.  
  81.     If lines < 3 Then
  82.        
  83.         If lines = 0 Then
  84.             For i = 1 To 3 - 1
  85.                 rows(top).Select
  86.                 Selection.Delete Shift:=xlUp
  87.             Next i
  88.        
  89.         Else
  90.             For i = 1 To 3 - lines
  91.                 rows(top).Select
  92.                 Selection.Delete Shift:=xlUp
  93.             Next i
  94.         End If
  95.     End If
  96.  
  97.     If lines > 3 Then
  98.         lines = lines - 3
  99.         ostatok = lines Mod 2
  100.         top = top + 1
  101.         ch_top = top
  102.         add_lines = top
  103.         While lines <> 0 And lines > 0
  104.             If add_lines - top > lines Then
  105.                 add_lines = top + lines - 1
  106.             End If
  107.             ch_add_lines = add_lines
  108.             range = ch_top + ":" + ch_add_lines
  109.             'If ostatok = 0 Then ' ÷åòíîå
  110.            rows(range).Select
  111.             'ElseIf ostatok = 1 Then ' íå÷åòíîå
  112.            'End If
  113.            Selection.Insert Shift:=xlDown
  114.             add_lines = add_lines + 1
  115.             c4ak = add_lines - top
  116.             all = all + c4ak
  117.             lines = lines - c4ak
  118.         Wend
  119.     End If
  120.  
  121.     'range("B1").Select
  122. End Sub
  123.  
  124.  
  125.  
  126.  
  127. Sub Merge_itog_str(top As Integer, strMyString As String)
  128.  
  129.   'Dim top As Integer
  130.  Dim Ik As Integer
  131.   Dim arrMyArray() As String
  132.   'Dim strMyString As String
  133.  'strMyString = "178/173/171/112/44/42/40/36/30/28/25/18/16/14/11/"
  134.  'strMyString = "4/6/7/" - òàê äîëæíà âûãëÿäåòü ñòðîêà 178/173/171/112/44/42/40/36/30/28/25/18/16/14/11/
  135.  arrMyArray = Split(strMyString, "/")
  136.  
  137. For Ik = LBound(arrMyArray) To UBound(arrMyArray) - 1
  138. Worksheets("P01").range(Cells(arrMyArray(Ik) + top - 1, 2), Cells(arrMyArray(Ik) + top - 1, 9)).Select
  139. K = K + 1
  140. Dim irow As range, icel As range, MergeVal As String
  141.  Application.DisplayAlerts = False
  142.    For Each irow In Selection.rows
  143.      For Each icel In irow.Cells
  144.        If icel.Value <> "" Then MergeVal = MergeVal & icel.Value & " "
  145.      Next icel
  146.    If MergeVal <> "" Then irow(1).Value = left(MergeVal, Len(MergeVal) - 1)
  147.    MergeVal = ""
  148.    irow.Merge
  149.    Next irow
  150. Selection.rows.AutoFit
  151. Selection.HorizontalAlignment = xlLeft
  152. Selection.rows.Font.Bold = True
  153.  Application.DisplayAlerts = True
  154.  'Application.DisplayAlerts = True
  155.  
  156.  
  157.  
  158. Worksheets("P01").range(Cells(arrMyArray(Ik) + top - 1, 1), Cells(arrMyArray(Ik) + top - 1, 33)).Select
  159.  Selection.rows.Font.Bold = True
  160. Next Ik
  161. range("B1").Select
  162.  
  163. End Sub
  164.  
  165.  
  166.  
  167.  
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement