改成这样就可以了:
Sub aaa()
Range("a1").Select
For a = 1 To 7
For b = 1 To 7
For c = 1 To 7
For d = 1 To 7
Do While a < b And a < c And a < d And b < c And b < d And c < d
Sum = Format(a, "00 ") & Format(b, "00 ") & Format(c, "00 ") & Format(d, "00") '修改部分
ActiveCell.Value = Sum
ActiveCell.Offset(1, 0).Select
Exit Do
Loop
Next
Next
Next
Next
End Sub
Sub aaa()
Range("a1").Select
For a = 1 To 7
For b = 1 To 7
For c = 1 To 7
For d = 1 To 7
Do While a < b And a < c And a < d And b < c And b < d And c < d
Sum = a & b & c & d
ActiveCell.Value = Sum
ActiveCell.Offset(1, 0).Select
Exit Do
Loop
Next
Next
Next
Next
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(2, 1), Array(3, 1)), _
TrailingMinusNumbers:=True
Columns("A:D").Select
Selection.NumberFormatLocal = "00"
Selection.Rows.AutoFit
Selection.Columns.AutoFit
End Sub
我这个是按你的要求显示的,并且
四个数据分别显示在 ABCD四列里,方便你统计
另外你的要求不是任意四个数吗?
那按排列组合计算是C 4上标 7 下标 那是840个呢
可是那段代码才30几个
都是从大到小排的
我感觉应该
把Do While a < b And a < c And a < d And b < c And b < d And c < d
改成
Do While a <> b And a <>c And a <> d And b <>c And b <>d And c <>d
就是840个了