Dim fs As Object, folder As Object, file As Object Dim ws As Worksheet Dim i As Integer…
- User
Dim fs As Object, folder As Object, file As Object Dim ws As Worksheet Dim i As Integer Dim textFile As Integer Dim fileContent As String Dim RegEx As Object Dim matches As Object
' Ensure references to the active worksheet and FileSystemObject Set ws = ThisWorkbook.Sheets("Sheet1") Set fs = CreateObject("Scripting.FileSystemObject") ' Using the folder where the workbook is saved Set folder = fs.GetFolder(ThisWorkbook.Path) ' Start writing from row 2 in column G i = 2 For Each file In folder.Files If LCase(fs.GetExtensionName(file.Name)) = "txt" Then textFile = FreeFile() Open file.Path For Input As textFile fileContent = "" fileContent = Input(LOF(textFile), textFile) Close textFile ' Debug output to help diagnose the issue Debug.Print "Content of " & file.Name & ": " & fileContent Set RegEx = CreateObject("VBScript.RegExp") With RegEx .Global = True .IgnoreCase = True .Pattern = "Placed\s*:\s*(\d+)" End With Set matches = RegEx.Execute(fileContent) If matches.Count > 0 Then Dim numericValue As String numericValue = matches(0).SubMatches(0) ' Debug print the captured value for verification Debug.Print "Captured Numeric Value: " & numericValue ' Write captured numeric value into column G starting from row 2 ws.Cells(i, 7).Value = numericValue i = i + 1 Else ' If no match found, print a message Debug.Print "No match found in " & file.Name End If ' Clean up RegExp object after use Set RegEx = Nothing End If Next file ' Clean up FileSystemObject after use Set fs = Nothingfor this code i want before to paste values in column g to search for names of files on b cells and to put on same row numeric value on column g
- Assistant
- User
where is end sub ?
- Assistant
- User
i want all this to be part to only one code wich start with sub and end with end sub
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.