首页 热点资讯 义务教育 高等教育 出国留学 考研考公

怎样让excel里面单格里的数字从小到大排序

发布网友 发布时间:2022-04-21 07:55

我来回答

1个回答

热心网友 时间:2022-06-19 04:58

在此,提供一个使用VBA编写的“冒泡程序”,供你参考:
原始数据如图:
每个单元格6个数字,以逗号(,)分隔
VBA代码如下:
Sub
单元格排序()
'

Dim
shuzu(1
To
6)

hs
=
1

ls
=
1

dachuan
=
Cells(hs,
ls)

Do
While
Len(dachuan)
<>
0

zs
=
1

Do
While
zs
<=
6

fgf
=
InStr(dachuan,
",")

If
fgf
<>
0
Then

shuzu(zs)
=
Left(dachuan,
fgf
-
1)

dachuan
=
Right(dachuan,
Len(dachuan)
-
fgf)

Else

shuzu(zs)
=
dachuan

End
If

Cells(hs,
ls
+
1)
=
shuzu(zs)

ls
=
ls
+
1

zs
=
zs
+
1

Loop

jh
=
1

Do
While
jh
<
6

If
Val(shuzu(jh))
>
Val(shuzu(jh
+
1))
Then

lssz
=
shuzu(jh)

shuzu(jh)
=
shuzu(jh
+
1)

shuzu(jh
+
1)
=
lssz

jh
=
1

Else

jh
=
jh
+
1

End
If

Loop

Cells(hs,
ls
+
2)
=
shuzu(1)
&
","
&
shuzu(2)
&
","
&
shuzu(3)
&
","
&
shuzu(4)
&
","
&
shuzu(5)
&
","
&
shuzu(6)

zs
=
1

hs
=
hs
+
1

ls
=
1

dachuan
=
Cells(hs,
ls)

Loop
'
End
Sub
见图:
这段代码执行后的效果,见图:

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com