码迷,mamicode.com
首页 > 编程语言 > 详细

VBA 小知识

时间:2014-10-29 12:35:23      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   for   sp   数据   div   

1. 循环

Dim i As Integer

For i = 0 To 100
    body
Next

While i < 100
    body
Wend

 

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 = value(1)
        Me.Cells(i + 1, 3).value = value(2)
        Me.Cells(i + 1, 4).value = 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 小知识

标签:style   blog   io   color   ar   for   sp   数据   div   

原文地址:http://www.cnblogs.com/crazyghostvon/p/vba1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!