+ Reply to Thread
Results 1 to 9 of 9

Extracting summary to raw data

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2007
    Posts
    15

    Extracting summary to raw data

    Hi,

    I have a set of data which lists numerous dog breeds and the number of dogs with and without a disease.

    These values are all totalled and I don't have access to the raw data.

    However, I want to try and reproduce the raw data for some work I'm doing. So I want to generate a list of every single dog represented in the summary data showing their breed and disease status.

    This will take forever manually. Is there anyway to do this with VBA? I have attached an example of what I mean, including a manually produced example of the data I want to try and generate.

    Any help would be hugely appreciated.

  2. #2
    Registered User
    Join Date
    11-06-2007
    Posts
    15
    Sorry, I forgot to attach the file.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-06-2007
    Posts
    15
    Bump! Please help if you can, I don't know where to begin!

  4. #4
    Forum Contributor
    Join Date
    04-30-2008
    Posts
    105
    To be perfectly honest, that'd be a difficult macro (for me anyway) to write. From the way it looks, it seems possible for your raw report to require more rows than Excel even has.

  5. #5
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295
    No it will take 47348 rows...

    Mike

  6. #6
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295
    Try this macro:

    NB Rename your summary sheet to SUMMARY
    and create a sheet called DETAIL before you begin

    Sub Copydata()
         
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim improw2 As Long 
        
        Dim rList As Range, rCell As Range
        Dim n1 As Long, n2 As Long, v1 As Long, v2 As Long
        
        Application.ScreenUpdating = False
        
        v1 = 0
        v2 = 1
        
        Set ws1 = ActiveWorkbook.Sheets("Summary")
        Set ws2 = ActiveWorkbook.Sheets("Detail")
        Set rList = ws1.Range("A2", Range("A" & Rows.count).End(xlUp)) ' list
             
        'beginning location on ws2
        improw2 = 1
        
        For Each rCell In rList
        
            n1 = rCell.Offset(0, 1).Value
            n2 = rCell.Offset(0, 2).Value
            
            For I = 1 To n1
            
                rCell.Copy Destination:=ws2.Cells(improw2, 1)
                ws2.Cells(improw2, 2).Value = v1
                       
                improw2 = improw2 + 1
                
                
            Next I
            
            For j = 1 To n2
            
                
                rCell.Copy Destination:=ws2.Cells(improw2, 1)
                ws2.Cells(improw2, 2).Value = v2
                 
                improw2 = improw2 + 1
                 
            Next j
        
        Next rCell
                
        
        Application.ScreenUpdating = True
        
    End Sub
    Last edited by Mikeopolo; 06-10-2008 at 05:02 AM.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    try
    Sub test()
    Dim a, i As Long, b(), n As Long, ii As Long
    a = Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(,3).Value
    ReDim b(1 To Application.Sum(Range("b:c")), 1 To 2)
    For i = 2 To UBound(a,1)
        For ii = 1 To a(i,2)
            n = n + 1
            b(n,1) = a(i,1) : b(n,2) = 0
        Next
        For ii = 1 To a(i,3)
            n = n + 1
            b(n,1) = a(i,1) : b(n,2) = 1
        Next
    Next
    Range("f1").Resize(n,2).Value = b
    End Sub
    Last edited by jindon; 06-10-2008 at 06:00 AM.

  8. #8
    Forum Contributor
    Join Date
    01-18-2005
    Location
    Auckland New Zealand
    MS-Off Ver
    Office Professional 2007
    Posts
    295
    Jindon, that's a neat method, will study it closely!

    Nucleotide_boy, do you need any help getting these macros installed and running?

    Regards
    MIke

  9. #9
    Registered User
    Join Date
    11-06-2007
    Posts
    15
    Quote Originally Posted by jindon
    try
    Sub test()
    Dim a, i As Long, b(), n As Long, ii As Long
    a = Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(,3).Value
    ReDim b(1 To Application.Sum(Range("b:c")), 1 To 2)
    For i = 2 To UBound(a,1)
        For ii = 1 To a(i,2)
            n = n + 1
            b(n,1) = a(i,1) : b(n,2) = 0
        Next
        For ii = 1 To a(i,3)
            n = n + 1
            b(n,1) = a(i,1) : b(n,2) = 1
        Next
    Next
    Range("f1").Resize(n,2).Value = b
    End Sub

    That is absolutely perfect. Thank you so much!

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