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