PDA

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



blastpwr1970
06-13-2006, 12:57 PM
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 :help me with this.



'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





Please help
Julio

blastpwr1970
06-13-2006, 04:28 PM
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.


'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

mdmackillop
06-14-2006, 04:22 AM
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

blastpwr1970
06-14-2006, 06:02 AM
Thank you all, you have been very helpful.
Especial thank's to mdmackillop and DRJ.
:beerchug:
Julio