Results 1 to 10 of 10

Loop Through To Enter Data In Multiple Closed Workbooks

Threaded View

  1. #1
    Registered User
    Join Date
    09-16-2013
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    38

    Loop Through To Enter Data In Multiple Closed Workbooks

    Hi
    I currently use a macro where I enter the location ofa bunch of workbooks and it automatically changes a specific cell to what I require. The code is -
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim myrange As Range
        Dim Lastrow As Long
        Dim sFolder As String
        
        'folder where workbooks are stored
         'change as required (Ensure that the end of your link has the backslash otherwise code wont work)
        sFolder = "C:\\"
       
        Lastrow = Me.Cells(Me.Rows.Count, "A").End(xlUp).Row + 1
        If Lastrow < 4 Then Lastrow = 4
        Application.ScreenUpdating = False
        Set myrange = Me.Range("D13:D13" & Lastrow)
        If Not Intersect(Target, myrange) Is Nothing Then
            UpdateFilesInFolder Target, sFolder
        End If
        Application.ScreenUpdating = True
    End Sub
    
    Sub UpdateFilesInFolder(ByVal Target As Range, ByVal sFolder As String)
        Dim strFile As String
        
        strFile = Dir(sFolder & "*.xlsx", vbNormal)
    
        Do While strFile <> ""
            If strFile <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(sFolder & strFile, ReadOnly:=False)
            
            With wb
                .Worksheets("Total Quantities").Range(Target.Address).Value = Target.Value
                .Close True
            End With
            End If
            strFile = Dir
        Loop
    End Sub
    This works well but when I have sub folders it will not search through those folders and update any workbooks which are in those. I am also wanting to make it so instead of entering the location manually I would just click a button instead and browse the directory the excel workbooks are stored. What coding do I need to change so that it will work in the way I am describing. I hope this makes sense. Any help will be greatly appreciated
    Last edited by Tristanfrontline; 03-15-2015 at 08:15 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Get Data from Multiple Closed Workbooks
    By groundin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 12:27 PM
  2. Vba to extract data from multiple closed workbooks
    By The1theycallp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2013, 07:49 AM
  3. Copy Data to One Workbook From Multiple Closed Workbooks
    By Ben4481 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2010, 08:02 AM
  4. [SOLVED] Importing data from multiple closed workbooks
    By Judy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-29-2005, 06:50 PM

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