Results 1 to 3 of 3

Search for string in several workbooks and retrieve data from another column?

Threaded View

  1. #1
    Registered User
    Join Date
    04-22-2018
    Location
    Stockholm.Sweden
    MS-Off Ver
    Office 365
    Posts
    3

    Search for string in several workbooks and retrieve data from another column?

    Hi there,
    I am a beginner in excel Macros and need support.

    I have 10 excel workbooks in one folder and each workbook contains approx 32 worksheets.

    I need to search for a certain string in column A in all workbooks and worksheets and retrieve the data that in column D.
    My end result I would like to have is something like the below.
    Workbook Worksheet "Value in column D"
    a xx "Value xx"
    b yy "Value yy"
    c zz "Value ZZ"


    I found the below formulas that almost fulfills my needs with the exception that it shows the value that I search for but I need the value in column D in the same row. See below for .Cells(xRow, 3)=....

    I hope that someone can support.

    Br Thomas

    Sub SearchFolders()

    Dim xFso As Object
    Dim xFld As Object
    Dim xStrSearch As String
    Dim xStrPath As String
    Dim xStrFile As String
    Dim xOut As Worksheet
    Dim xWb As Workbook
    Dim xWk As Worksheet
    Dim xRow As Long
    Dim xFound As Range
    Dim xStrAddress As String
    Dim xFileDialog As FileDialog
    Dim xUpdate As Boolean
    Dim xCount As Long
    On Error GoTo ErrHandler
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a forlder"
    If xFileDialog.Show = -1 Then
    xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    xStrSearch = "Sum Telecom equipment Services fees"
    xUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    Set xOut = Worksheets.Add
    xRow = 1
    With xOut
    .Cells(xRow, 1) = "Workbook"
    .Cells(xRow, 2) = "Worksheet"
    .Cells(xRow, 3) = "Text in Cell"
    Set xFso = CreateObject("Scripting.FileSystemObject")
    Set xFld = xFso.GetFolder(xStrPath)
    xStrFile = Dir(xStrPath & "\*.xls*")
    Do While xStrFile <> ""
    Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
    For Each xWk In xWb.Worksheets
    Set xFound = xWk.UsedRange.Find(xStrSearch)
    If Not xFound Is Nothing Then
    xStrAddress = xFound.Address
    End If
    Do
    If xFound Is Nothing Then
    Exit Do
    Else
    xCount = xCount + 1
    xRow = xRow + 1
    .Cells(xRow, 1) = xWb.Name
    .Cells(xRow, 2) = xWk.Name
    .Cells(xRow, 3) = xFound.Value
    End If
    Set xFound = xWk.Cells.FindNext(After:=xFound)
    Loop While xStrAddress <> xFound.Address
    Next
    xWb.Close (False)
    xStrFile = Dir
    Loop
    .Columns("A:D").EntireColumn.AutoFit
    End With
    MsgBox xCount & "cells have been found", , "Kutools for Excel"
    ExitHandler:
    Set xOut = Nothing
    Set xWk = Nothing
    Set xWb = Nothing
    Set xFld = Nothing
    Set xFso = Nothing
    Application.ScreenUpdating = xUpdate
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub
    Last edited by ESEKOCK; 04-22-2018 at 01:22 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Urgent support please: How to run Macros continously?
    By corelotti in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2016, 05:12 PM
  2. Does Excel 2016 for Mac support XLM macros?
    By riwiseuse in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2016, 10:37 AM
  3. Class does not support Automation or does not support expected interface
    By ccs_1981 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2015, 05:57 AM
  4. Office 365 doesn't support Excel Macros
    By Salasobor in forum Office 365
    Replies: 1
    Last Post: 09-10-2013, 08:44 AM
  5. runtime 430 error- Class does not support Automation or does not support...
    By kimcole5 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2012, 01:27 PM
  6. [SOLVED] Languages support in Macros
    By Swamy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2005, 02:05 PM
  7. [SOLVED] i am interested in buying PDA that support micosoft excel macros
    By mOHAMMAD aKBAR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2005, 01:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1