Results 1 to 8 of 8

Adjust existing macro to pick up specific named worksheet and copy to named range

Threaded View

Groovicles Adjust existing macro to pick... 06-06-2017, 11:06 AM
jolivanes Re: Adjust existing macro to... 06-06-2017, 12:09 PM
Groovicles Re: Adjust existing macro to... 06-06-2017, 12:49 PM
jolivanes Re: Adjust existing macro to... 06-06-2017, 01:33 PM
Groovicles Re: Adjust existing macro to... 06-06-2017, 03:23 PM
jolivanes Re: Adjust existing macro to... 06-06-2017, 06:45 PM
jolivanes Re: Adjust existing macro to... 06-07-2017, 12:24 PM
jolivanes Re: Adjust existing macro to... 06-08-2017, 12:03 PM
  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Adjust existing macro to pick up specific named worksheet and copy to named range

    Hi everyone,

    I have an existing macro which works pretty well. I currently run through all workbooks in a folder, identifies worksheet names which match worksheet names in the master workbook and copies the data from the external workbook worksheet to the master workbook worksheet. What I'm trying to do is adjust the macro to do the following:

    1. run through each workbook in a folder
    2. if the workbook name equals a cell value in ThisWorkbook.Sheet1.range("B2:B50") then copy Worksheet("ABC") entire used range into Workbooks(2) with the worksheet that matches the external workbook name.
    3. move to the next cell in the range and repeat as above

    So for example, lets cell B2 in ThisWorkbook.Sheet1.range("B2:B50") = "Stuff"
    The macro will find workbook.name = "Stuff" and copy the used range in Workbooks("Stuff").Worksheets("ABC")
    The master will paste this used range into Workbooks(2).Worksheets("Stuff")
    Then move onto the cell B3 in ThisWorkBook.Sheet1.range("B2:B50")

    Below is the macro as I have it. It doesn't work with the adjustments I've tried to make:

    Option Explicit
    Sub Update_Summary()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim myPath As String, myFile As String, myExtension As String
    Dim FldrPicker As FileDialog
    Dim FilePicker As FileDialog
    Dim rng As Range
    Dim cell As Range
    
      Application.ScreenUpdating = False
      Application.EnableEvents = False
      Application.DisplayAlerts = False
      Application.Calculation = xlCalculationManual
      
        MsgBox ("Please select Summary File")
    
        myFile = Application.GetOpenFilename
    
        Workbooks.Open (myFile), UpdateLinks:=0
        
        Workbooks(1).Worksheets("Data").Range("D2").Value = ActiveWorkbook.Path
        
        Workbooks(1).Worksheets("Data").Range("D3").Value = ActiveWorkbook.Name
    
    rng = ThisWorkbook.Sheet1.Range("B2:B50")  
    Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
    
        With FldrPicker
          .title = "Select A Target Folder"
          .AllowMultiSelect = False
            If .Show <> -1 Then GoTo NextCode
            myPath = .SelectedItems(1) & "\"
        End With
    
    NextCode:
      myPath = myPath
      If myPath = "" Then GoTo ResetSettings
    
      myExtension = "*.xl*"
    
      myFile = Dir(myPath & myExtension)
    
      Do While myFile <> ""
          Set wb = Workbooks.Open(Filename:=myPath & myFile)
          
          For Each cell In rng
            On Error Resume Next
            If ExistBook(wb.Name) Then
                If wb(ws.Name) = "Rollup" Then
                    wb.Sheets("ABC").UsedRange.Copy
                    Workbooks(2).Sheets(cell.Name).Range("A1").PasteSpecial xlValues
                End If
            End If
          On Error GoTo 0
          wb.Close savechanges:=False
          Next cell
    
          
          DoEvents
    
          myFile = Dir
      Loop
    
      MsgBox "Task Complete!"
    
    ResetSettings:
        Application.EnableEvents = True
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    
    End Sub
    Function ExistBook(sWs$, Optional sWb As Workbook) As Boolean
             If sWb Is Nothing Then Set sWb = ActiveWorkbook
             On Error Resume Next
             ExistBook = IsObject(sWb.Sheets(sWs))
    End Function
    Any ideas?

    Thanks!!
    Last edited by Groovicles; 06-06-2017 at 11:11 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] vba code to add modulable no of named worksheets after the last existing named sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2017, 08:48 AM
  2. Copy values of all named range in wb1 to identically named ranges in wb2
    By JAMIAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2016, 06:58 PM
  3. Copy specific cell(s) or named range from one workbook to another
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2012, 06:01 PM
  4. Replies: 3
    Last Post: 06-04-2011, 10:56 AM
  5. Adding a new row into an existing named range in a macro
    By topper in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2009, 10:25 AM
  6. Need to adjust existing named range for dynamic charts
    By tbonejo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2006, 12:18 PM
  7. create named range specific to worksheet
    By beliavsky@aol.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2005, 12:05 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