首页 > 代码库 > VBA 小知识

VBA 小知识

1. 循环

Dim i As IntegerFor i = 0 To 100    bodyNextWhile i < 100    bodyWend

 

2. 键值数据结构

    create dictionary object    Set dictMembers = CreateObject("scripting.dictionary")    add a key    If Not dictMembers.exists(Key) Then        add value        Dim value(1 To 3) As Integer        tempdata(1) = 0        tempdata(2) = 0        tempdata(3) = 0        dictMembers.Add Key, value    End If        Dim keys()    keys = dictMembers.keys        read dictionary    Dim value    For i = 0 To dictMembers.Count - 1        Key = keys(i)        value = dictMembers.Item(keys(i))        Me.Cells(i + 1, 2).value = http://www.mamicode.com/value(1)        Me.Cells(i + 1, 3).value = http://www.mamicode.com/value(2)        Me.Cells(i + 1, 4).value = http://www.mamicode.com/value(3)    Next

3. 数据图表chart

get the first chart    Me.ChartObjects(1).Activate    ‘set datasource    ActiveChart.SetSourceData Source:=Range("A8:F" & i - 1)    While ActiveChart.SeriesCollection.Count > 2        ‘remove useless series        ActiveChart.SeriesCollection(1).Delete        ActiveChart.SeriesCollection(1).Delete        ActiveChart.SeriesCollection(1).Delete    Wend    display value    ActiveChart.SeriesCollection(1).ApplyDataLabels    ActiveChart.SeriesCollection(2).ApplyDataLabels

 

VBA 小知识