+ Reply to Thread
Results 1 to 3 of 3

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

  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.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Begiiner in Macros and need support.

    Duplicate post.
    Last edited by Logit; 04-22-2018 at 12:58 PM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Begiiner in Macros and need support.

    ESEKOCK, welcome to the forum.

    Unfortunately your post doesn't comply with following Forum Rules.

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ Reply to Thread

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