EXCEL VBA函数问题,高手来帮忙!
如图,在B1单元格,用VBA编写一个函数,或直接一个数组函数,可删除A列的重复项,在B1中生成一个数组?...
如图,在B1单元格,用VBA编写一个函数,或直接一个数组函数,可删除A列的重复项,在B1中生成一个数组?
展开
3个回答
展开全部
Function mcqc(rng As Range)
Set d = CreateObject("Scripting.Dictionary")
For Each a In rng
d(a.Value) = ""
Next
mcqc = Join(d.keys, ";")
End Function
=MCQC(区域)
追问
谢谢,可以达到我的要求,但还想再请教下,如何在生成数组的每个值左右,再加上引号能?如{"1";"a";"2";"3";"b";"c";"d":}
追答
道理一样,后面修改一下就可以了
Function mcqc(rng As Range)
Set d = CreateObject("Scripting.Dictionary")
For Each a In rng
d(a.Value) = ""
Next
mcqc = "{""" & Join(d.keys, """;""") & """}"
End Function
展开全部
在B1列中生成一个数组?能办到吗。如果B1中得到图中一样的字符串倒是不难
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub tests()
Dim rst As String
rst = "{" & Cells(1, 1) & ";"
i = 2
Do While Cells(i, 1) <> ""
If Len(rst) = Len(Replace(rst, Cells(i, 1), "")) Then
rst = rst & Cells(i, 1) & ";"
End If
i = i + 1
Loop
rst = Left(rst, Len(rst) - 1)
rst = rst & Cells(i, 1) & "}"
Cells(1, 2) = rst
End Sub
Dim rst As String
rst = "{" & Cells(1, 1) & ";"
i = 2
Do While Cells(i, 1) <> ""
If Len(rst) = Len(Replace(rst, Cells(i, 1), "")) Then
rst = rst & Cells(i, 1) & ";"
End If
i = i + 1
Loop
rst = Left(rst, Len(rst) - 1)
rst = rst & Cells(i, 1) & "}"
Cells(1, 2) = rst
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询