[Vba]excel the selected data and all combinations for a given number

Source: Internet
Author: User

Yesterday afternoon began to learn the VBA, exhausted, there must be bugs, to be debugged

The VBA program is as follows:

1 DimAsum as Integer2 DimTSum as Integer3 DimJudge -) as Integer4 DimArrmax as Integer5 Dimarr6 DimLocation -) as Integer7 8 FunctionTest ()9     DimArrwmax as IntegerTen     DimRng asRange One     DimBeginrow as Integer A     DimBeginline as Integer -      -     SetRng = Application.inputbox (prompt:="Please Select ....", type:=8) theRR =rng.address -Beginrow =Rng.column -Beginline =Rng.row -      +arr =Range (RR) -Asum =0 +Arrmax =UBound(arr) AArrwmax =UBound(Arr,2) at  -      forLoca =1  toArrmax -Location (Loca) =Beginline -Beginline = Beginline +1 -     Next -      in      forCol =2  toArrwmax'Modify -TSum = Arr (1, col) to         PagerSubtest (1, Beginrow) +     Next -  the End Function *  $ FunctionSubtest (n as Integer, Beginrow as Integer)Panax Notoginseng     IfAsum > TSum Then -         Exit Function the     End If +  A     DimI as Integer the     DimJ as Integer +     IfAsum = TSum Then -          fori =1  toN $             IfJudge (i) =1  Then $Sheets (1). Cells (Location (i), Beginrow). Interior.Color =vbred -             End If -         Next the  -         Exit FunctionWuyi     End If the  -     Ifn = Arrmax Then Wu         Exit Function -     End If About  $      forj = N toArrmax -         IfJudge (j) =0  Then -Judge (j) =1 -Asum = Asum + arr (j,1) A             PagerSubtest (J, Beginrow) +  theJudge (j) =0 -Asum = Asum-arr (J,1) $             IfJ < Arrmax Then the                  whileArr (J,1) = Arr (j +1,1) thej = j +1 the Wend the             End If -         End If in     Next the  the End Function

[Vba]excel the selected data and all combinations for a given number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.