Results 1 to 3 of 3

Find all specified cell values in directory of workbooks, paste text in offset column

Threaded View

Telemanes Find all specified cell... 06-20-2020, 06:15 PM
AlphaFrog Re: Find all specified cell... 06-20-2020, 10:45 PM
Telemanes Re: Find all specified cell... 06-21-2020, 06:44 AM
  1. #1
    Registered User
    Join Date
    07-24-2017
    Location
    Stamford, UK
    MS-Off Ver
    2016
    Posts
    7

    Find all specified cell values in directory of workbooks, paste text in offset column

    Hi There,

    I was wondering if someone could please help me with my VBA code that is not working - The reason why is beyond my skill level. Having extensively looked to tweak other peoples code I am still not getting the result I need. I will try to be as concise as possible: I have some software that generates reports from a large database, generating multiple workbooks for each section, and multiple sheets within each for subsections (The only way the software will do this unfortunately). I have attached a pseudonym example of what I might get out of one spreadsheet.

    What I need to do is write some VBA code which will go through all the workbooks within a folder, find any instance of a customer ID (input box) and then change the value (Input box) of the cell 3 columns to the right (this is a fixed offset). As a pseudonym example, I might want to make a comment on all workbooks/worksheets that a specific person had an issue flag up with their account. This would mean anyone accessing these reports would have this helpful note. Each ID could appear in any selection of workbooks(and worksheets within each workbook)

    I copied some code from two different sources in the below example, but it only opens all the workbooks.

    Sub LoopThroughFiles()
        Dim myID As Variant
        myID = InputBox("Enter Customer ID")
        Dim myResponse As Variant
        meResponse = InputBox("Enter the comment to be entered in all instances")
        Dim xFd As FileDialog
        Dim xFdItem As Variant
        Dim xFileName As String
    'Select Folder containing workbooks
        Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
        If xFd.Show = -1 Then
            xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
            xFileName = Dir(xFdItem & "*.xlsx*")
            Do While xFileName <> ""
                With Workbooks.Open(xFdItem & xFileName)
                
    'What to do in each workbook
    Dim Sh As Worksheet
    Dim Loc As Range
    
    For Each Sh In ThisWorkbook.Worksheets
    With Sh.UsedRange
            Set Loc = .Cells.Find(What:=myID)
            If Not Loc Is Nothing Then
                Do Until Loc Is Nothing
                    Loc.Offset(0.3).Value = myResponse
    		ActiveWorkbook.Save
                    Set Loc = .FindNext(Loc)
                    Loop
                    End If
                    End With
                    Set Loc = Nothing
                    Next
    'End of routine within each workbook
    
                End With
                xFileName = Dir
            Loop
        End If
    End Sub
    Thank you so much in advance for any help with this
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA: Look for partial text in Column A from Column B and paste text offset Column A
    By coryspeth in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-07-2018, 05:53 AM
  2. copy multiple ranges, find next empty cell in first column and paste values as text
    By Zlatko.Pan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2018, 06:13 PM
  3. Replies: 1
    Last Post: 02-04-2014, 01:57 PM
  4. [SOLVED] Find text in column A then copy the cell to the right and paste it in sheet2
    By Alring in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-22-2013, 02:11 AM
  5. Loop to find a cell, then copy offset paste
    By mr.alexander in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-29-2013, 08:48 AM
  6. Replies: 0
    Last Post: 09-06-2012, 04:06 AM
  7. code to find text, offset 1 column and paste to new workbook not working
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2011, 07:55 AM

Tags for this Thread

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