+ Reply to Thread
Results 1 to 4 of 4

Summary report by Name and Category in VBA

  1. #1
    Registered User
    Join Date
    11-19-2012
    Location
    Dubai
    MS-Off Ver
    2016
    Posts
    5

    Summary report by Name and Category in VBA

    Hi All,

    I have data in a sheet where I need to summarize this data by name and category within two dates, I have done it by name, but I also need it by name and category within specified dates. I have attached a workbook with my code.
    The code for the summary by name works perfectly, I need help to summarize by name going down the rows and category by columns within the specified dates. Please keep the code simple for me to understand.
    My file is attached.


    Thanks in advance.
    Mustafa



    Please Login or Register  to view this content.
    Sub UsingDates2()


    Dim sht As Worksheet
    Dim lastrow As Long
    Dim names() As String
    Dim namecount As Long
    Dim rptsht As Worksheet
    Dim x As Long
    Dim i As Long
    Dim currentname As String
    Dim totals() As Long
    Dim startdate As Integer
    Dim enddate As Integer
    Dim rng As Range


    Set sht = Sheets("Sales")

    'rpthsht is the output sheet
    Set rptsht = Sheets("By Date")


    startdate = sht.Cells.Find(what:=rptsht.Range("A2"), LookIn:=xlValues).Column ' there is an input cell for the start date
    enddate = sht.Cells.Find(what:=rptsht.Range("B2"), LookIn:=xlValues).Column ' there is an input cell for the end date


    lastrow = sht.Cells(Rows.Count, 1).End(xlUp).Row


    rptsht.Range("D:E").Columns.Clear


    sht.Range("A1:A" & lastrow).AdvancedFilter _
    xlFilterCopy, copytorange:=rptsht.Range("D2"), Unique:=True


    With rptsht.Range("D2")
    namecount = Range(.Offset(1, 0), .Offset(1, 0).End(xlDown)).Rows.Count
    ReDim names(namecount)
    ReDim totals(namecount)
    For x = 1 To namecount
    names(x) = .Offset(x, 0).value
    Next x
    End With




    With sht.Range("A1")
    For x = 1 To Range(.Offset(1, 0), .Offset(1, 0).End(xlDown)).Rows.Count
    currentname = .Offset(x, 0).value

    For i = 1 To namecount
    If currentname = names(i) Then
    Set rng = sht.Cells(x + 1, startdate).Resize(1, (enddate - startdate + 1))
    totals(i) = totals(i) + .Offset(x, 2).value * _
    Application.WorksheetFunction.Sum(sht.Range(rng.Address))
    End If
    Next i


    Next x
    End With


    With rptsht.Range("D2")
    .Offset(0, 1).value = "Totals"
    For i = 1 To namecount
    .Offset(i, 1).value = totals(i)
    Next i
    Range(.Offset(0, 0), .Offset(0, 1).End(xlDown)).Select
    End With

    End Sub
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by chriscorpion786; 05-30-2018 at 05:07 AM. Reason: according to rules

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Summary report by Name and Category in VBA

    Unfotunately, your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Please amend 1st post so we can continue to help you.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    11-19-2012
    Location
    Dubai
    MS-Off Ver
    2016
    Posts
    5

    Re: Summary report by Name and Category in VBA

    Dears,
    I have edited according to the rules you have specified and attached my file.

    Thank you for your reply.
    Mustafa

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,084

    Re: Summary report by Name and Category in VBA

    But you have not added the code tags requested.

    And ...

    Rule 08: Cross-posting Without Telling Us

    Your post does not comply with Rule 8 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question. If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    No further help to be offered, please, until the OP has complied with this request.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Replies: 0
    Last Post: 10-14-2015, 12:53 PM
  2. Need to automate a report to generate top 3 by category. Help!
    By agalloch123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2014, 08:00 AM
  3. Convert Detailed Time Attendance report from Biometrics to Summary Report
    By firescorpio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2013, 02:48 AM
  4. chart with summary of min/max and average values by data category
    By RogerL in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 11-24-2012, 04:58 PM
  5. Category summary for 12 pivot tables
    By MeScott in forum Excel General
    Replies: 3
    Last Post: 07-24-2010, 03:08 AM
  6. Form Email from Report, Only if Report summary sheet lists Acct for that Sales Rep
    By lukep10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2008, 01:38 PM
  7. how to generate report based on adding costs of particular category
    By hoser in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-20-2007, 06:58 PM

Tags for this Thread

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