早教吧 育儿知识 作业答案 考试题库 百科 知识分享

共14个数,七组数如何选出不重复的三组数1,2,3,3,4,5,6,7,9,8,10,11,12,13以下7组1,32,34,56,78,910,1112,13比如:1,34,56,7三组为一个,统计出不重复的三组数的个数,每组的数字不能改变,三个组中的数字不

题目详情
共14个数,七组数如何选出不重复的三组数
1,2,3,3,4,5,6,7,9,8,10,11,12,13
以下7组
1,3
2,3
4,5
6,7
8,9
10,11
12,13
比如:1,3 4,5 6,7 三组为一个,统计出不重复的三组数的个数,每组的数字不能改变,三个组中的数字不能有相同的,列出三组为一个组合的个数.用EXECL公式表达出来
▼优质解答
答案和解析
可以用如下代码实现:
Sub pailie()
c = WorksheetFunction.CountA(Range("A:A"))
n = ActiveSheet.Name
cl = 2
For x = 1 To c
a1 = Range("A" & x)
a1l = Left(a1,WorksheetFunction.find(",",a1) - 1)
a1r = Right(a1,WorksheetFunction.find(",",a1) - 1)
For y = x + 1 To c
a2 = Range("A" & y)
a2l = Left(a2,WorksheetFunction.find(",",a2) - 1)
a2r = Right(a2,WorksheetFunction.find(",",a2) - 1)
If a1l = a2l Or a1l = a2r Then GoTo yy
If a1r = a2l Or a1r = a2r Then GoTo yy
For z = y + 1 To c
a3 = Range("A" & z)
a3l = Left(a3,WorksheetFunction.find(",",a3) - 1)
a3r = Right(a3,WorksheetFunction.find(",",a3) - 1)
If a1l = a3l Or a1l = a3r Then GoTo zz
If a1r = a3l Or a1r = a3r Then GoTo zz
If a2l = a3l Or a2l = a3r Then GoTo zz
If a2r = a3l Or a2r = a3r Then GoTo zz
Sheets(n).Cells(1,cl) = a1
Sheets(n).Cells(2,cl) = a2
Sheets(n).Cells(3,cl) = a3
cl = cl + 1
zz:
Next z
yy:
Next y
Next x
End Sub
运行时一定要注意选择当前表,可以在A列增加或改动数据,但格式要与现在保持一致,即"X,Y"的格式