Private Sub CommandButton1_Click()

 Dim ws As Worksheet
    Dim cell As Range
    Dim lastRow As Long
    Dim RegEx As Object
    Dim matches As Object
    Dim match As Variant

    ' Initializing the Regular Expression object
    Set RegEx = CreateObject("VBScript.RegExp")
    With RegEx
        .Global = False ' Find only the first match
        .IgnoreCase = True ' Case-insensitive matching
        .Pattern = "(\d+)(FOI|TAIERI)" ' Pattern to find number directly before FOI or TAIERI
    End With

    ' Set reference to the required worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")
    lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row

    ' Loop through each cell in Column B
    For Each cell In ws.Range("B1:B" & lastRow)
        If RegEx.Test(cell.Value) Then
            Set matches = RegEx.Execute(cell.Value)
            For Each match In matches
                ' Write the numeric part to Column A
                cell.Offset(0, -1).Value = match.SubMatches(0)
                Exit For ' Exit after the first match to ensure only one number is written per cell
            Next match
        Else
            cell.Offset(0, -1).Value = "" ' Mark cells where no pattern was matched
        End If
    Next cell

    MsgBox "Process completed. Check Column A."
End Sub

Private Sub CommandButton2_Click()
  
    Dim wsTarget As Worksheet
    Dim wsLog As Worksheet
    Dim wbSource As Workbook
    Dim wsSource As Worksheet
    Dim strFile As String
    Dim fileDialog As fileDialog
    Dim lastRow As Long
    Dim sourceRange As Range
    Dim targetRange As Range
    Dim logRow As Long
    
    Application.ScreenUpdating = False
    
    ' Seteaz? foaia ?int? unde vrei s? copiezi datele
    Set wsTarget = ThisWorkbook.Sheets(1) 'Presupunând c? este prima foaie
    ' Seteaz? foaia pentru log
    Set wsLog = ThisWorkbook.Sheets("Sheet2")
    
    ' Ini?ializeaz? dialogul pentru selectarea fi?ierului
    Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
    
    With fileDialog
        .AllowMultiSelect = False
        .Title = "Selecteaza un fisier .xlsx"
        .Filters.Add "Fisiere Excel", "*.xlsx"
        
        If .Show = -1 Then ' Dac? utilizatorul selecteaz? un fi?ier
            strFile = .SelectedItems(1) ' Ob?ine calea complet? a fi?ierului selectat
            
            ' Deschide fi?ierul .xlsx selectat
            Set wbSource = Workbooks.Open(Filename:=strFile)
            Set wsSource = wbSource.Sheets(1)
            
            ' Determin? ultimul rând utilizat pe foaia ?int? pentru a începe copierea datelor dincolo de acest punct
            lastRow = wsTarget.Cells(wsTarget.Rows.Count, 1).End(xlUp).Row
            
            ' Seteaz? gama surs? de copiat (doar valorile, nu ?i formatarea)
            Set sourceRange = wsSource.UsedRange
            
            ' Stabile?te gama ?int? unde vor fi copiate datele
            Set targetRange = wsTarget.Cells(lastRow + 1, 1)
            
            ' Copiaz? valorile din surs? în ?int? f?r? a aduce formatarea sau formulele
            sourceRange.Copy
            targetRange.PasteSpecial Paste:=xlPasteValues
            
            Application.CutCopyMode = False ' Anuleaz? modul de copiere
            
            ' Închide fi?ierul .xlsx
            wbSource.Close SaveChanges:=False
            
            ' Logheaz? calea fi?ierului surs? în Sheet2
            logRow = wsLog.Cells(wsLog.Rows.Count, 2).End(xlUp).Row + 1
            ' Asigur? c? începi de la B1 dac? este gol
            If logRow = 1048577 Then logRow = 1
            wsLog.Cells(logRow, 2).Value = strFile
            
            MsgBox "Datele au fost copiate cu succes din " & strFile
        Else
            MsgBox "Niciun fisier nu a fost selectat."
        End If
    End With
    
    Application.ScreenUpdating = True
End Sub




Private Sub CommandButton3_Click()

    Dim wsLog As Worksheet, wsData As Worksheet
    Dim lastRowLog As Long, lastRowData As Long, r As Long, i As Long
    Dim folderPath As String, txtFileName As String, xlsxFileName As String
    Dim fileContent As String
    Dim startNum As Integer, placedValue As String
    
    ' Set?m sheet-urile
    Set wsLog = ThisWorkbook.Sheets("Sheet2")
    Set wsData = ThisWorkbook.Sheets("Sheet1")
    
    ' Determin?m ultimul rând folosit pe fiecare sheet
    lastRowLog = wsLog.Cells(wsLog.Rows.Count, 2).End(xlUp).Row
    lastRowData = wsData.Cells(wsData.Rows.Count, 2).End(xlUp).Row
    
    For r = 1 To lastRowLog
        folderPath = wsLog.Cells(r, 2).Value
        If Right(folderPath, 1) <> "" Then folderPath = folderPath & ""
        
        For i = 1 To lastRowData
            xlsxFileName = wsData.Cells(i, 2).Value
            
            If Len(xlsxFileName) > 0 Then
                txtFileName = folderPath & Left(xlsxFileName, Len(xlsxFileName) - 4) & ".txt"
                
                If Dir(txtFileName) <> "" Then
                    ' Deschide ?i cite?te con?inutul fi?ierului .txt
                    Open txtFileName For Input As #1
                    fileContent = Input(LOF(1), #1)
                    Close #1
                    
                    ' Extrage valoarea numeric? dup? "Placed:"
                    startNum = InStr(fileContent, "Placed:") + Len("Placed:")
                    placedValue = Mid(fileContent, startNum)
                    placedValue = Trim(Val(placedValue)) ' Extrage ?i converte?te la num?r
                    
                    ' Scrie valoarea numeric? în coloana G
                    wsData.Cells(i, 7).Value = placedValue
                End If
            End If
        Next i
    Next r
    
    MsgBox "NR DE PIESE ACTUALIZAT."
End Sub






PT acest cod as dori sa completezi ca in momentul in care fisierele   .txt nu au fost gasite msg box"FISIERELE .TXT NU AU FOST GASITE- VERIFICA DACA AU FOST CREATE " SI RENUNTA LA COMANDA