+ Reply to Thread
Results 1 to 3 of 3

VBA that can generate (Only the Report )

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    VBA that can generate (Only the Report )

    Using Excel 2010
    Hello,

    I have got VBA code which generate all possible combination form 4 sets under this link https://www.excelforum.com/excel-pro...ml#post5953979

    Does is it possible…to have VBA code which can generate (Only the report) without generating all combinations as shown in the column I:M… (Only the report in column O:P) if once the report has generated I can chose min-max range easily…

    Here is workbook attached with an example.

    Please help.

    Regards,
    Moti
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,862

    Re: VBA that can generate (Only the Report )

    A "quick fix": using Data Dictionary might (will) be slightly quicker.

    Another example of not thinking clearly what is REALLY required!

    Option Explicit
    
    Sub demo1() 'By JohnTopley
    
    Dim i As Long, ii As Long, iii As Long, iiii As Long, n As Long, j As Long, lr As Long
    Dim a, b
    Const srow As Long = 6
    
    Application.ScreenUpdating = False
    
    lr = Cells(Rows.Count, 3).End(xlUp).Row
    
    a = Range("C" & srow & ":F" & lr)
    
    ReDim b(1 To 30000, 1 To 5)
    
    
    For i = 1 To Cells(Rows.Count, 3).End(xlUp).Row - srow + 1
        For ii = 1 To Cells(Rows.Count, 4).End(xlUp).Row - srow + 1
            For iii = 1 To Cells(Rows.Count, 5).End(xlUp).Row - srow + 1
                For iiii = 1 To Cells(Rows.Count, 6).End(xlUp).Row - srow + 1
                    n = n + 1
                    b(n, 1) = a(i, 1): b(n, 2) = a(ii, 2): b(n, 3) = a(iii, 3): b(n, 4) = a(iiii, 4)
                    For j = 1 To 4
                        b(n, 5) = b(n, 5) + b(n, j)
                    Next j
                Next iiii
            Next iii
        Next ii
    Next i
    
    
    [I6].Resize(30000, 5).Clear
    [I6].Resize(n, 5) = b
    [I6].Resize(n, 5).Borders.Weight = 2
    Columns(9).Resize(, 5).HorizontalAlignment = xlCenter
    
    [M6].Resize(n, 1).Copy [O6]
    [O6].Resize(n, 1).RemoveDuplicates Columns:=1, Header:=xlYes
    n = Cells(Rows.Count, "O").End(xlUp).Row - 5
    [O5].Resize(n + 1, 1).Sort key1:=[O5], order1:=xlAscending, Header:=xlYes
    
    With [P6].Resize(n, 1)
    .Formula = "=COUNTIF(M:M,O6)"
    .Value = .Value
    End With
    
    Columns(15).Resize(, 2).HorizontalAlignment = xlCenter
    
    [I1].Resize(30000, 5).Clear
    
    Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files
    Last edited by JohnTopley; 05-30-2024 at 07:31 AM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: VBA that can generate (Only the Report )

    Quote Originally Posted by JohnTopley View Post
    A "quick fix": using Data Dictionary might (will) be slightly quicker.
    @JohnTopley, this work great! It recognizes the length of each group automatically. This is very helpful. I feel grateful for your kind help. Good luck.

    Quote Originally Posted by JohnTopley View Post
    Another example of not thinking clearly what is REALLY required!
    I really accept my mistakes; I always think after I get answer for next step…next time I will be thinking all at once may be. Sorry for the inconveniences. This is solved 100%

    My Best regards,
    Moti

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help to Generate Report
    By kunal.patni in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-31-2018, 08:12 AM
  2. VBA : Displays blank report after click "Generate Report" from excel to Word document
    By suchetherrah in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2016, 08:00 AM
  3. Generate Report using vba
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2010, 10:22 AM
  4. Excel 2007 : Need to generate a report
    By Zipmeister in forum Excel General
    Replies: 0
    Last Post: 01-20-2010, 08:51 AM
  5. [SOLVED] Generate Report
    By Peter Carlson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-12-2006, 01:00 AM
  6. Generate Report
    By Peter Carlson in forum Excel General
    Replies: 0
    Last Post: 04-10-2006, 01:55 PM
  7. generate report
    By raisin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2005, 01:47 AM

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