Consulting

Results 1 to 4 of 4

Thread: Solved: If text then perform this, if not then skip.

  1. #1

    Solved: If text then perform this, if not then skip.

    Hi All,

    I have a line of code that it suppouse to subtotal but when it tries to subtotal it tell me that the the command can not be completed using the specified range, so what I think, I have to do is bypass the subtotal if there is no data to subtotal, could somebody me with this.

    [VBA]

    'Subtotal code
    Range("E1").Select
    Selection.RemoveSubtotal
    Range("E1").Select

    Selection.Subtotal GroupBy:=23, Function:=xlCount, TotalList:=Array(23), _
    Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    Selection.Subtotal GroupBy:=23, Function:=xlSum, TotalList:=Array(20), _
    Replace:=False, PageBreaks:=False, SummaryBelowData:=True


    [/VBA]


    Please help
    Julio
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

  2. #2

    Smile Solve:If text then perform this, if not then skip.

    Sorry for the inconvineance.

    I figure it out, like I said, I am just getting my feet wet in learning VBA.

    This is what I wanted.

    [VBA]
    'Subtotal code
    If Range("A2") > 0 Then

    Range("E1").Select
    Selection.RemoveSubtotal
    Range("E1").Select

    Selection.Subtotal GroupBy:=23, Function:=xlCount, TotalList:=Array(23), _
    Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    Selection.Subtotal GroupBy:=23, Function:=xlSum, TotalList:=Array(20), _
    Replace:=False, PageBreaks:=False, SummaryBelowData:=True

    End If
    [/VBA]
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Julio,
    You will commonly return errors from code, both unintentionally and deliberately. Check "Err" in VBA Help, for guidance in how to use this to continue or exit your code, or carry out other operations as required.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Thank you all, you have been very helpful.
    Especial thank's to mdmackillop and DRJ.

    Julio
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •