Results 1 to 6 of 6

Data Sorting to a Specific Format

Threaded View

  1. #1
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Data Sorting to a Specific Format

    The code below sorts data for me but I will need a modification so as to achieve my new goal.
    From the attached spreadsheet, the first tab called “data” is the data that I want to sort in a particular format. The second tab called “Results” is what I sorted already with the old code, while the third tab “Preferred” is the actual thing that I need.
    This is what I need:
    Whenever the macro meets a cell that has no value in it, it should replace the blank cell with “1*” also whenever the macro meets a cell that has the same date (as you can see that the orange cells have the same date as the gray rows), instead of outputting the result as shown in “Results” tab, I want the macro to combine these rows as shown in the “preferred” tab.
    Also you can see that the yellow cell has the same date as “1-Feb-07” I will like to combine it as shown in the preferred tab.
    Thanks a lot for your help.
    Below is my code:
    Sub test1()
        Dim a, i&, n&, m&, arr, j&
        j = 0
        m = Range("A" & Rows.Count).End(xlUp).Row
    
        With Range("A2", Range("A" & Rows.Count).End(xlUp)).Resize(m * 7, 30)
            a = .Value
    
            For i = 1 To UBound(a, 1)
                If a(i, 1) = "" Then GoTo oops
                n = n + 1
                a(i + j, 14) = "DATES"
                arr = Split(a(i, 5), "/")
                If Len(arr(1)) = 1 Then
                    a(i + 1 + j, 14) = "'0" & arr(1) & "  " & UCase(MonthName(arr(0), True)) & "  " & arr(2) & "  /"
                Else
                    a(i + 1 + j, 14) = "'" & arr(1) & "  " & UCase(MonthName(arr(0), True)) & "  " & arr(2) & "  /"
                End If
                a(i + 2 + j, 14) = "'/"
                a(i + 3 + j, 14) = a(i, 2)
                a(i + 4 + j, 14) = "    " & a(i, 1)
                a(i + 4 + j, 15) = a(i, 3)
                a(i + 4 + j, 15) = a(i, 3)
                a(i + 4 + j, 16) = a(i, 4)
                a(i + 4 + j, 17) = a(i, 6)
                a(i + 4 + j, 18) = a(i, 7)
                a(i + 4 + j, 19) = a(i, 8)
                a(i + 4 + j, 20) = a(i, 9)
                a(i + 4 + j, 21) = a(i, 10)
                a(i + 4 + j, 22) = a(i, 11)
                a(i + 4 + j, 23) = a(i, 12)
                a(i + 4 + j, 24) = "'/"
                a(i + 5 + j, 14) = "'/"
                
                If a(i, 6) = "" Then a(i + 4 + j, 17) = "'1*"
                If a(i, 7) = "" Then a(i + 4 + j, 18) = "'1*"
                If a(i, 8) = "" Then a(i + 4 + j, 19) = "'1*"
                If a(i, 9) = "" Then a(i + 4 + j, 20) = "'1*"
                If a(i, 10) = "" Then a(i + 4 + j, 21) = "'1*"
                If a(i, 11) = "" Then a(i + 4 + j, 22) = "'1*"
                If a(i, 12) = "" Then a(i + 4 + j, 23) = "'1*"
                
                j = j + 6
    
            Next
    oops:
            .Value = a
            Columns("N:Y").Select
            Selection.Cut
            Sheets("Results").Select
            Range("A1").Select
            ActiveSheet.Paste
            Columns("B:K").HorizontalAlignment = xlCenter
            Range("A1").Select
        End With
    End Sub
    Attached Files Attached Files
    Last edited by vnzerem; 12-05-2014 at 05:10 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with specific macro script for data copying in a specific format
    By Amit1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2014, 12:36 AM
  2. Sorting data from specific row
    By mubashar in forum Excel General
    Replies: 2
    Last Post: 07-14-2013, 01:00 PM
  3. Excel 2007 : Sorting by specific data with cells
    By chris108 in forum Excel General
    Replies: 2
    Last Post: 09-28-2010, 07:25 PM
  4. Sorting specific data from one sheet to another
    By JOUIOUI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2006, 07:10 PM
  5. Sorting specific data
    By [email protected] in forum Excel General
    Replies: 3
    Last Post: 06-10-2005, 01: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