Excel中VBA相关函数的使用
生活随笔
收集整理的這篇文章主要介紹了
Excel中VBA相关函数的使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
自定義函數(shù)實(shí)例-單元顏色求和(字典+自定義函數(shù))
Function COLORSUM(單元格區(qū)域 As range, 匯總的顏色 As range) Set d = CreateObject("Scripting.Dictionary") For Each Rng In 匯總的顏色d(Rng.Interior.ColorIndex) = "" Next For Each ci In d.keysFor Each Rng In 單元格區(qū)域If Rng.Interior.ColorIndex = ci Thenr = r + Rng.ValueEnd IfNextNext COLORSUM = r End Function Sub test() Set d = CreateObject("Scripting.Dictionary") Set 區(qū)域 = Application.InputBox("區(qū)域選擇", , , , , , , 8) Set 顏色 = Application.InputBox("顏色選擇", , , , , , , 8) For Each Rng In 顏色d(Rng.Interior.ColorIndex) = "" Next For Each ci In d.keysFor Each Rng In 區(qū)域If Rng.Interior.ColorIndex = ci Thenr = r + Rng.ValueEnd IfNextNext MsgBox rEnd Sub自定義函數(shù)實(shí)例-反轉(zhuǎn)字符與數(shù)字求和(正則+自定義函數(shù))
Function 求和(rng As Range, Optional s As String = "") Application.VolatileSet regx = CreateObject("vbscript.regexp") With regx.Global = True.Pattern = "\d" & sSet mat = .Execute(rng) End With For Each m In mat n = n + m * 1 Next 求和 = n End Function Function DD(rng As Range) '反轉(zhuǎn)字符 For i = Len(rng) To 1 Step -1a = Mid(rng, i, 1)b = b & a NextDD = b End Function自定義函數(shù)實(shí)例-提取不重復(fù)值(字典+正則+自定義函數(shù))
Function 不重復(fù)2(rng As Range, Optional num As Integer = 0) Set d = CreateObject("scripting.dictionary") Set regx = CreateObject("vbscript.regexp") With regx.Global = TrueIf num = 0 Then.Pattern = ".+" '所有值的不重復(fù)ElseIf num = 1 Then.Pattern = "[一-龢]+" '漢字不重復(fù)ElseIf num = 2 Then.Pattern = "[a-zA-Z]+" '字母不重復(fù)ElseIf num = 3 Then.Pattern = "\d+" '數(shù)字不重復(fù)End If For Each rn In rngFor Each m In .Execute(rn)d(m.Value) = ""Next Next 不重復(fù)2 = d.keys End With End Function Function 不重復(fù)值(rng As Range) Set d = CreateObject("scripting.dictionary") For Each rn In rngd(rn.Value) = "" Next 不重復(fù)值 = d.keys End Function總結(jié)
以上是生活随笔為你收集整理的Excel中VBA相关函数的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Kali安装magescan评估工具
- 下一篇: [react] 举例说明在react中怎