+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: Get data from diferent workbooks to a single workbook

  1. #16
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Get data from diferent workbooks to a single workbook

    Apologising is one thing but that's one of the worst crimes against fashion I've ever had the misfortune to witness.

    It suits you

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  2. #17
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Get data from diferent workbooks to a single workbook

    Good enough.

  3. #18
    Registered User
    Join Date
    09-14-2004
    Posts
    14

    Re: Get data from diferent workbooks to a single workbook

    The edit was not meant to arm anyone, i simply erase the lines in the top of the macro, i already edited the code and putted it back.

    i opened a new thread since the original one was solved, nevertheless , lesson learned !

    the code is like this at the moment :

    
    Sub CollectInfoFinal()
    
    'Author:    Jerry Beaucaire, ExcelForum.com
    'Date:      10/21/2010
    'Summary:   Collect specific data from all workbooks in a single folder
    
    Dim fPath As String
    Dim fName As String
    Dim wbData As Workbook
    Dim wsDest As Worksheet:    Set wsDest = ThisWorkbook.Sheets("stock")
    Dim NR As Long:             NR = wsDest.Range("B" & Rows.Count).End(xlUp).Row + 1
    Dim LR As Long
       
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = "C:\"
        .Show
        If .SelectedItems.Count > 0 Then
            fPath = .SelectedItems(1)
        Else
            MsgBox "Folder selection cancelled", vbInformation, Title:="Process Cancelled"
            Exit Sub
        End If
    End With
    
    Application.ScreenUpdating = False      'speed up macro
    fName = Dir(fPath & "\*.xls")            'filter for files to open
    
    Do While Len(fName) > 0
        Set wbData = Workbooks.Open(fPath & "\" & fName)  'open found file
        With wbData.Sheets("Resumo")
            .Rows(10).AutoFilter
            .Rows(10).AutoFilter Field:=6, Criteria1:=">0.5"
            LR = .Range("A" & .Rows.Count).End(xlUp).Row
            If LR > 10 Then
                wsDest.Range("A" & NR).Value = .[A5]
                wsDest.Range("E" & NR).Value = .[D2]
                .Range("A11:A" & LR & ",F11:F" & LR & ",K11:K" & LR).Copy
                wsDest.Range("B" & NR).PasteSpecial xlPasteValuesAndNumberFormats
                wsDest.Range("F" & NR).Value = .[C*E]
                
            End If
        End With
        wbData.Close False
        NR = Range("B" & Rows.Count).End(xlUp).Row + 1
        fName = Dir
    Loop
    
    LR = Range("B" & Rows.Count).End(xlUp).Row
    With Range("A1:E" & LR)
        .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
        .Value = .Value
    End With
    
    Run [teorico()]
    Run [real()]
    
    Columns.AutoFit
    Application.ScreenUpdating = True
    
    End Sub

  4. #19
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Get data from diferent workbooks to a single workbook

    Heh, I gave up calling my stuff "final"...there's always some new little tweak or feature to add. Cheers.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #20
    Registered User
    Join Date
    09-14-2004
    Posts
    14

    Re: Get data from diferent workbooks to a single workbook

    yes , its true ...its never final ....
    now i am checking some more details e want to add .... to rename the sheet with the actual date and some more small things that are now growing in my mind. but the main thing was the code you gave me ! without it ....
    once again Thanks

  6. #21
    Registered User
    Join Date
    09-14-2004
    Posts
    14

    Re: Get data from diferent workbooks to a single workbook

    missed to post the code for the 2 sub macros i inserted in the main code :

    
    Sub teorico()
    Dim r As Range
    Set r = Range("F2", Cells(Rows.Count, "F").End(xlUp)).Offset(0, 0)
    r.Formula = "=C2*E2"
    r.Copy
    r.PasteSpecial xlValues
    End Sub
    Sub real()
    Dim r As Range
    Set r = Range("F2", Cells(Rows.Count, "F").End(xlUp)).Offset(0, 1)
    r.Formula = "=D2*E2"
    r.Copy
    r.PasteSpecial xlValues
    End Sub

  7. #22
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Get data from diferent workbooks to a single workbook

    Maybe this:
    Sub teorico()
        With Range("F2", Cells(Rows.Count, "F").End(xlUp))
            .Formula = "=C2*E2"
            .Value = .Value
        End With
    End Sub
    Sub real()
        With Range("F2", Cells(Rows.Count, "F").End(xlUp)).Offset(0, 1)
           .Formula = "=D2*E2"
            .Value = .Value
        End With
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0