+ Reply to Thread
Results 1 to 17 of 17

vba subtotal

  1. #1
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    vba subtotal

    Hello to all,
    is possible with vba:

    if cell A:A contains "conteggio" (count)
    next cell B copy B-1
    next cell C copy C-1

    see Attachment
    john
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: vba subtotal

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hi ikboy thanks for the reply, your macro not work

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    Try....
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    I Cr76 work well.
    A change for cell 47 does not have to be entered
    Attached Files Attached Files

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    Just change Range() to... (add -1 so that last row is ignored)
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hi CK76 work well
    check lines 275/276 in new attached
    275 is missing
    276 is not needed

    changed in macro "conteggio"> "totale"
    Attached Files Attached Files

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    You have - 2 in your range. Should be - 1.

  9. #9
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    oops
    Thanks CK76 it works
    thank you again
    john

  10. #10
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hi,

    Please Login or Register  to view this content.
    if not found here it gives error.

    For Each cel In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row - 1)

    is it possible to add if it does not find an invalid file message and exits the macro?

  11. #11
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hello maybe I explained myself wrong?

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    Yes, please give more detail. It isn't clear to me what exactly is needed.
    And FYI, I don't check forum on weekends and on holidays (Monday was Canadian stat holiday).

  13. #13
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hi CK76 your macro if there is a subtotal in the file works well
    if it doesn't contain a subtotal it gives error here
    For Each cel In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row - 1)
    Is possible an message box for warnin error?

  14. #14
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    ? If error is given there, then it isn't subtotal that's issue.

    But your A column not having any value(s) to loop over that's causing issue. Add if statement that wrap For Each loop.

    So that loop executes only when there's enough data.
    Ex:
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Hi CK76 tanks you, your macro work well:
    Please Login or Register  to view this content.
    in the meantime I did this:


    Please Login or Register  to view this content.
    for you is correct?

  16. #16
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba subtotal

    I prefer to remove exit sub line and nest your error step in If Err.Number <> 0 then...
    Otherwise looks fine
    Last edited by CK76; 02-18-2020 at 03:18 PM.

  17. #17
    Forum Contributor
    Join Date
    10-31-2018
    Location
    venezia
    MS-Off Ver
    2007
    Posts
    487

    Re: vba subtotal

    Thanks for the info CK76.
    A greeting and thanks again.
    xam

+ 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. Sorting by Alpha, Adding Subtotal - then removing subtotal - variable data sets
    By gregg_grug in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2019, 07:41 PM
  2. Remove only 1 subtotal layer from Multi Nested Subtotal
    By goawohl in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 10-16-2014, 10:10 AM
  3. need subtotal to also include the matching data in subtotal line
    By baby_kay_2003 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-15-2014, 12:43 AM
  4. Replies: 1
    Last Post: 09-18-2013, 04:10 PM
  5. Replies: 8
    Last Post: 07-31-2012, 09:41 AM
  6. Subtotal - Delete zero Subtotal and prior rows that calculate to that zero Subtotal
    By Whatsherface in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2012, 08:37 PM
  7. Replies: 3
    Last Post: 03-08-2006, 05:25 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