Private Function regexpmulti(S As Variant) ' ' Dim Sl As String, bRes As Boolean, RegExp As Object, oMatches As Object, n As Integer, P As String, Text As String, TextReplace As String Sl = "" ReDim x(1) As String bRes = False Set RegExp = CreateObject("VBScript.RegExp") ' RegExp.Global = True RegExp.IgnoreCase = False ' RegExp.Pattern = TextBox1.Text ' TextBox1.Text - On Error Resume Next ' bRes = RegExp.test(S) If ComboBox1.Text = "" Then ' , p P = 0 Else P = ComboBox1.Text End If If OptionButton2 Then ' " /" Text = "" TextReplace = TextBox2.Text Else Text = TextBox2.Text End If If bRes Then Set oMatches = RegExp.Execute(S) ' ' If P = 0 Or P > 5 Then ' Sl Sl = oMatches(0) & Text ' For n = 1 To oMatches.Count - 1 Sl = Sl & oMatches(n) & Text ' Next ElseIf P = 1 Then Sl = oMatches(0).subMatches(0) & Text For n = 1 To oMatches.Count - 1 Sl = Sl & oMatches(n).subMatches(0) & Text Next ElseIf P = 2 Then Sl = oMatches(0).subMatches(0) & oMatches(0).subMatches(1) & Text For n = 1 To oMatches.Count - 1 Sl = Sl & oMatches(n).subMatches(0) & oMatches(n).subMatches(1) & Text Next ElseIf P = 3 Then Sl = oMatches(0).subMatches(0) & oMatches(0).subMatches(1) & oMatches(0).subMatches(2) & Text For n = 1 To oMatches.Count - 1 Sl = Sl & oMatches(n).subMatches(0) & oMatches(n).subMatches(1) & oMatches(n).subMatches(2) & Text Next End If If OptionButton2 Then ' S = RegExp.Replace(S, TextReplace) ' TextReplace - End If End If Set RegExp = Nothing ' If OptionButton4 Then ' "/" ' If Sl <> x(0) Then x(0) = Sl: x(1) = "" regexpmulti = x Else x(0) = Sl: x(1) = "" regexpmulti = x End If Else x(0) = Sl: x(1) = S regexpmulti = x End If End Function Private Sub ComboBox1_DropButtonClick() ComboBox1.List = Array("0", "1", "2", "3") ' ComboBox1.style = fmStyleDropDownList ' End Sub Private Sub ComboBox2_DropButtonClick() ComboBox2.List = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z") ComboBox2.style = fmStyleDropDownList End Sub Private Sub CommandButton1_Click() ' On Error GoTo Error ' . . ' Dim R, c Dim M(), RZ(), U(), S, P As String If ComboBox2.Text = "" Then ' S = "A" ' , A Else S = ComboBox2.Text End If P = S & "1" & ":" & S ' "A1:A" M = ActiveSheet.Range(P & ActiveSheet.Range(S & Rows.Count).End(xlUp).Row).Value ' RZ - , , . ReDim RZ(1 To UBound(M), 1 To UBound(M, 2) + 1) ' For R = 1 To UBound(M) If OptionButton3 Or OptionButton4 Then RZ(R, 1) = M(R, 1) ' End If c = regexpmulti(M(R, 1)) ' . "M(R, 1)" - If OptionButton2 Then ' - If ComboBox1.Text > 0 Then RZ(R, 1) = c(0) & c(1) Else RZ(R, 1) = c(1) End If End If If OptionButton3 Then RZ(R, 2) = c(0) End If If OptionButton1 Then RZ(R, 1) = c(1) RZ(R, 2) = c(0) End If If OptionButton4 Then RZ(R, 2) = c(1) End If Next R If CheckBox1.Value = True Then ' , Worksheets.Add ' Range("A1").Resize(UBound(RZ), UBound(RZ, 2)) = RZ ' Else Range(S & "1").Resize(UBound(RZ), UBound(RZ, 2)) = RZ End If ' \ \ Cells.Columns.AutoFit Cells.Rows.AutoFit GoTo Skip ' Error: ' MsgBox " . - ", vbCritical, ", =(" GoTo 111 ' (Unload Me) , Skip: Unload Me 111: End Sub Private Sub Label2_Click() End Sub Private Sub OptionButton1_Click() Label2.ForeColor = &H80000012 ' Label* Label3.ForeColor = &H80000012 Label3.Caption = ":" ' Label* Label2.ControlTipText = " - . - '\s?\d{3}( )\s'. , - ." Label3.ControlTipText = " ." ' ComboBox1.Enabled = True ComboBox1.BackColor = vbWindowBackground TextBox2.Enabled = True TextBox2.BackColor = vbWindowBackground End Sub Private Sub OptionButton2_Click() Label2.ForeColor = &H80000012 Label3.ForeColor = &HFF& Label3.Caption = " :" Label2.ControlTipText = " - . - '\s?\d{3}( )\s'. 0 - , ." Label3.ControlTipText = " , ." ComboBox1.Enabled = True ComboBox1.BackColor = vbWindowBackground TextBox2.Enabled = True TextBox2.BackColor = vbWindowBackground End Sub Private Sub OptionButton3_Click() Label3.ForeColor = &H80000012 Label2.ForeColor = &H80000012 Label3.Caption = ":" Label2.ControlTipText = " - . - '\s?\d{3}( )\s'. , - ." Label3.ControlTipText = " ." ComboBox1.Enabled = True ComboBox1.BackColor = vbWindowBackground End Sub Private Sub OptionButton4_Click() Label3.ForeColor = &H80000000 Label2.ForeColor = &H80000000 Label2.ControlTipText = " - ." Label3.ControlTipText = " - ." ComboBox1.Enabled = False ' ComboBox ComboBox1.BackColor = vbButtonFace ' TextBox2.Enabled = False TextBox2.BackColor = vbButtonFace End Sub
Source: https://habr.com/ru/post/239369/
All Articles