excel数据汇编

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:34:07
A1 质数:3 2 7
A2 质数 5 7
A3 偶数 4 6 8
A4 奇数 1 3
A5偶数 12 14
如何在 B1 将 所有
质数

合数
偶数的
标签数据全部汇编在一起

举例
B1=质数:3 2 7
质数 5 7
B2偶数 4 6 8 偶数 12 14
B3=奇数 1 3
有一点需要说明的是 A列的数据 属无须排列 质数合数都不是固定在固定的单元格的

设计工作表命令按钮,并输入如下程序:
Private Sub CommandButton1_Click()
Dim rag As Range
Range("B1:B4").ClearContents
For Each rag In Range("A:A")
If rag.Value = "" Then Exit For
If InStr(rag.Value, "质数") > 0 Then
Range("B1").Value = Range("B1").Value & Trim(rag.Value) & " "
End If
If InStr(rag.Value, "偶数") > 0 Then
Range("B2").Value = Range("B2").Value & Trim(rag.Value) & " "
End If
If InStr(rag.Value, "奇数") > 0 Then
Range("B3").Value = Range("B3").Value & Trim(rag.Value) & " "
End If
If InStr(rag.Value, "合数") > 0 Then
Range("B4").Value = Range("B4").Value & Trim(rag.Value) & " "
End If
Next
End Sub