惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - VeryDxZ

创业公司做数据分析(转载) 初始化一台linux server来做项目管理和测试 Tanglement, although optional 自用Excel VBA函数整理 part3 灰常不错的SC2剧情分析 Sketching & Story telling [VBA] 1-MSScriptControl 2-JSON Got the whole picture of what I'm doing 自用Excel VBA技巧整理 - VeryDxZ - 博客园 自用Excel VBA函数整理 part2 论文没抽中盲检,心情爽多了 又到了Intern大批离职的时候,真伤感额 几个提高Windows(主要是XP)桌面产能的小软件 好久不碰Blog,最近要二次毕业了,继续写点警醒自己的话 Michael Joseph Jackson (August 29, 1958 – June 25, 2009) 第一次租房子,人生哦~ Me on twitter Collective Intelligence,一个牛逼的新马甲 许久没认真上网,发现网络还是挺有正面用途的
自用Excel VBA函数整理 part1
VeryDxZ · 2009-11-22 · via 博客园 - VeryDxZ

用于二维的Dictionary:

CreateOrSet2

HasValue2

数字-字母格式的列号互转:

ColNumToStr

ColStrToNum

字符串连接(类似String.Format()用{0}{1}等做占位符,实现得很土):

StrFormat

StrCat

在Workbook中保存基本类型值:

SetName, GetName

函数指针(用VB->Win API->VB的模拟,参考[1][2]):

另外Application.Run、CallByNameEvalEvaluate可能更实用,VB6/VBA杂就没一个像js或py那样的全能eval()函数呢。。。

Fn4及例子

初级版ArrayList(类模块):

Class ArrayList

Private arr() As Variant
Private size, capacity As IntegerPrivate Sub Class_Initialize()
    size 
= 0
    capacity 
= 10
    
ReDim arr(1 To capacity)
End SubPublic Property Get Count() As Integer
    Count 
= size
End PropertyPublic Property Get Item(idx)
    Item 
= arr(idx)
End PropertyPublic Property Let Item(idx, vlu)
    arr(idx) 
= vlu
End PropertyPublic Property Set Item(idx, obj)
    
Set arr(idx) = obj
End PropertyPublic Sub Add(elem)
    EnsureCapacity
    size 
= size + 1
    
    
If IsObject(elem) Then
        
Set arr(size) = elem
    
Else
        arr(size) 
= elem
    
End If
End SubPrivate Sub EnsureCapacity()
    
If (size + 1> capacity Then
        
ReDim Preserve arr(1 To capacity * 2'Preserve!
        capacity = capacity * 2
    
End If
End SubPublic Sub Clear()
    size 
= 0
End SubPublic Function IndexOf(elem) As Long
    idx
& = -1
    elemObj 
= IsObject(elem)
    
    
For i = 1 To size
        
If elemObj Then
            
If IsObject(arr(i)) Then
                
If ObjPtr(arr(i)) = ObjPtr(elem) Then
                    idx 
= i
                    
Exit For
                
End If
            
End If
        
Else
            
If Not IsObject(arr(i)) Then
                
If arr(i) = elem Then
                    idx 
= i
                    
Exit For
                
End If
            
End If
        
End If
    
Next i

    IndexOf 

= idx
End FunctionPublic Sub Delete(elem)
    idx 
= IndexOf(elem)
    
If idx <> -1 Then
        DeleteAt idx
    
End If
End SubPublic Sub DeleteAt(idx)
    
For i = idx To (size - 1)
        
If IsObject(arr(i + 1)) Then
            
Set arr(i) = arr(i + 1)
        
Else
            arr(i) 
= arr(i + 1)
        
End If
    
Next i
    size 
= size - 1
End SubPublic Function GetArray()
    
Dim ret() As Variant
    
ReDim ret(1 To size)
    
For i = 1 To size
        ret(i) 
= arr(i)
    
Next i
    
    GetArray 
= ret
End Function

运行一个SQL查询并填充到工作表上:

ExecuteSelect

Public Sub ExecuteSelect(connStr, selectTxt, destTopLeft As Range)
    
On Error GoTo ExecuteSelect_Err
    
Set ws = destTopLeft.Worksheet
    
    
Set conn = CreateObject("ADODB.Connection")
    conn.Open connStr
    
Set rs = conn.Execute(selectTxt)
    
    
For i = 0 To rs.Fields.Count - 1
        destTopLeft.Offset(
0, i) = rs.Fields(i).Name
    
Next i
    destTopLeft.Offset(
10).CopyFromRecordset rs

ExecuteSelect_Clean:

If Not IsEmpty(rs) Then
        rs.Close
    
End If
    
If Not IsEmpty(rs) Then
        conn.Close
    
End If
    
Set rs = Nothing
    
Set conn = Nothing
    
Exit Sub
ExecuteSelect_Err:
    
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
    
GoTo ExecuteSelect_Clean
End Sub