Results 1 to 24 of 24

VBA script for collation of data

Threaded View

  1. #1
    Registered User
    Join Date
    05-08-2008
    Posts
    12

    VBA script for collation of data

    Hi guys :
    I've been working on a requirement that involves, collating data from multiple sales reps and consolidating them into one file. Once this collation is done, we would be using this worksheet to generate reports . This is required on a monthly basis
    I managed to find some code on the web , that helps me collate the data, but need help in these two aspects :
    1) I'm able to collate the data from multiple sheets (it is appended in the same worksheet), but i loose the header in the master sheet. The header will be in the same lines as
    Sl No Sales Rep Customer Product Month Unit Price Qty
    How can i ensure that the master has this header and the collation of data starts after their headers.

    2) On running of the macro, all files open up and remains open after the data is collected on the master. How can i close the sheets after the master has been populated with data.

    3) Since the data is collected from multiple sheets, each users data have their line items numbered, but in the master sheet, we find that the numbering (Sl no) is not consistnt. How can i have a sequential numbering in column A for all data.

    Would appreciate any inputs , pointers in this regard...

    TIA.

    Sushesh

    The code that i use is :

    Sub Get_Value_From_All()
        Dim wbSource As Workbook
        Dim wbThis As Workbook
        Dim rToCopy As Range
        Dim uRng   As Range
        Dim rNextCl As Range
        Dim lCount As Long
         
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
             
            On Error Resume Next
             
            Set wbThis = ThisWorkbook
             'clear the range except  headers
            Set uRng = wbThis.Worksheets(1).UsedRange
            uRng.Offset(1, 0).Resize(uRng.Rows.Count - 1, _
            uRng.Columns.Count).Clear
            With .FileSearch
                .NewSearch
                 'Change path to suit
                .LookIn = "C:\Test"
                .FileType = msoFileTypeExcelWorkbooks
                 
                If .Execute > 0 Then 'Workbooks in folder
                    For lCount = 1 To .FoundFiles.Count ' Loop through all.
                         'Open Workbook x and Set a Workbook  variable to it
                        Set wbSource = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                        Set rToCopy = wbSource.Worksheets(1).UsedRange
                        Set rNextCl = wbThis.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(2, 0)
                        rToCopy.Offset(1, 0).Resize(rToCopy.Rows.Count - 1, _
                        rToCopy.Columns.Count).Copy rNextCl
                      
                        
                    Next lCount
                Else:  MsgBox "No workbooks found"
                End If
            End With
             
             
            On Error GoTo 0
            .ScreenUpdating = True
            .DisplayAlerts = True
            .EnableEvents = True
        End With
    End Sub
    Last edited by VBA Noob; 05-09-2008 at 01:25 AM.

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.6.0 RC 1