Results 1 to 6 of 6

Need help breaking a report into mulitple sorted/formatted reports

Threaded View

  1. #1
    Registered User
    Join Date
    03-15-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    25

    Need help breaking a report into mulitple sorted/formatted reports

    This is my first post so forgive me if I do anything incorrectly. I have a test file with about 50 records. Each record contains a serial number of a device and an application that is installed on that device as well as additional information. My ultimate goal is to have the macro break this report into individual reports for each workstation. In addition to that I would like certain records to be deleted and others sorted into sections based on whether or not the application appears in a preset list in another worksheet. I've attached 3 files. The Mock file contains the macro. It has 4 sheets (EXAMPLE, DELETE, SECTION1, SECTION2). TestFile contains test data. Machine1 contains what the macro currently outputs. Right now the output is just a sheet with the list of apps for a specific machine. Looking at the EXAMPLE worksheet you can see how I would like it ultimately formatted. Any apps present in the DELETE Worksheet should be deleted. Any apps in the REPLACE worksheet should have the replacement put in section 1. Any Apps in the SECTION2 worksheet should be put in Section 2. All remaining records should be put in Section 3. I've never used VBA but what code you see I was able to put together in a day and a half so i'm a quick learner. Any help would be appreciated!

    Note: some code is for future purposes such as SetHeaderInfo(). Also this requires a directory of "C:\WKSTEMP\" to save the files.

    Here is the current macro:

    Sub MultiFormat()
    '
    ' Keyboard Shortcut: Ctrl+m
    '
    ' This macro will process an exported report with multiple machine data into individual machine reports and save the reports using the MachineID as the file name.
    '
    ' Macro begins now...
    
    ' Dimension variables
    
    Dim OrigWS As String
    OrigWS = ActiveSheet.Name
        
    ' Strip Header Row
        Rows("1:1").Select
        Selection.Delete Shift:=xlUp
        
    ' Parse file
    
    'Based on column A, data is filtered to individual sheets
    'Creates sheets and sorts alphabetically in workbook
    Dim LR As Long, i As Long, MyArr
    Dim MyCount As Long, ws As Worksheet
    Application.ScreenUpdating = False
    
    Set ws = Sheets(OrigWS)      'edit to sheet with master data
    ws.Activate
    
    Rows(1).Insert xlShiftDown
    Range("A1") = "Key"
    Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("CC1"), Unique:=True
    Columns("CC:CC").Sort Key1:=Range("CC2"), Order1:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    MyArr = Application.WorksheetFunction.Transpose(Range("CC2:CC" & Rows.Count).SpecialCells(xlCellTypeConstants))
    
    Range("CC:CC").Clear
    Range("A1").AutoFilter
    
    For i = 1 To UBound(MyArr)
        ws.Range("A1").AutoFilter Field:=1, Criteria1:=MyArr(i)
        LR = ws.Range("A" & Rows.Count).End(xlUp).Row
        If LR > 1 Then
            If Not Evaluate("=ISREF('" & MyArr(i) & "'!A1)") Then
                Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = MyArr(i)
            Else
                Sheets(MyArr(i)).Move After:=Sheets(Sheets.Count)
                Sheets(MyArr(i)).Cells.Clear
            End If
            ws.Range("A2:A" & LR).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
                Sheets(MyArr(i)).Range("A1")
            ws.Range("A1").AutoFilter Field:=1
            MyCount = MyCount + Sheets(MyArr(i)).Range("A" & Rows.Count).End(xlUp).Row - 1
            Sheets(MyArr(i)).Columns.AutoFit
            SetHeaderInfo
            FormatData
            SaveTitleClose
        End If
    Next i
    
    ' Display success message
    
    ws.Activate
    ws.AutoFilterMode = False
    LR = ws.Range("A" & Rows.Count).End(xlUp).Row - 1
    Rows(1).Delete xlShiftUp
    MsgBox "Rows with data: " & LR & vbLf & "Your files have been created! Please check them."
    Application.ScreenUpdating = True
    
    ' Close the report data file
    
    ActiveWorkbook.Close Saved = True
    
    End Sub
    
    Public Function FormatData()
    ' Delete unused columns and rows
        Columns("A:K").Select
        Selection.Delete Shift:=xlToLeft
        Columns("G:I").Select
        Selection.Delete Shift:=xlToLeft
    ' Change font size
        Cells.Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ThemeColor = xlThemeColorLight1
            .TintAndShade = 0
            .ThemeFont = xlThemeFontMinor
        End With
    ' Set column width to auto
        Columns("A:G").Select
        Selection.Columns.AutoFit
    End Function
    
    Public Function SaveTitleClose()
    ' Save worksheet as new workbook, set title, and close.
        Dim wb As Workbook
        Dim Name As String
        Name = ActiveSheet.Name
        Worksheets(Name).Copy
        Set wb = ActiveWorkbook
        wb.BuiltinDocumentProperties("title") = Name & " Applications List"
        wb.SaveAs FileName:="C:\WKSTEMP\" & Name & ".xlsx", FileFormat:=51
        wb.Close
    ' Close the new worksheet
        Application.DisplayAlerts = False
        Worksheets(Name).Delete
        Application.DisplayAlerts = True
    
    End Function
    
    Public Function SetHeaderInfo()
        Dim UserID As String
        UserID = Range("B2").Value
        Dim UserDep As String
        UserDep = Range("D2").Value
    End Function
    Attached Files Attached Files

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