zoukankan      html  css  js  c++  java
  • 在Excel中引用其他宏

    在excel的使用过程中,会用到一些自定义函数,可以使用宏轻松的实现这些功能,问题是必须使用“启用宏的excel”,这样用户每次打开时都要启用宏。

    现用以按背景色计划为例,解决以上问题:

    1.新建一个空白的excel,按alt+F11,打开VB界面,点击“插入”---“模块”---录入以下代码:

    //这个方法是计算相同颜色的单元格个数

    Function CountColor(col As Range, countrange As Range) As Integer
    Dim icell As Range
    Application.Volatile
    For Each icell In countrange
    If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
    CountColor = CountColor + 1
    End If
    Next icell
    End Function

    //这个方法是计算相同颜色的单元格中的数据之和
    Function SumColor(col As Range, sumrange As Range) As Integer
    Dim icell As Range
    Application.Volatile
    For Each icell In sumrange
    If icell.Interior.ColorIndex = col.Interior.ColorIndex Then
    SumColor = Application.Sum(icell) + SumColor
    End If
    Next icell
    End Function

    在VB中点击保存,保存excel时选择“另存为”--“Excel 加载宏(*.xlam)”,把这个excel存储为sum.xlam文件。

    2.打开要计算的excel,在此中选择开发工具--加载宏--浏览--选择sum.xlam,选中,点确认。

    3.完成。

    4.这样操作以后,只要打开excel就可以使用sumColor这个函数,不用启用宏。

  • 相关阅读:
    Oracle EXP-00091解决方法
    Oracle 表空间的概念
    每天一点点oracle
    ntp服务问题
    Centos 7.4 安装samba服务
    Oracle group by
    Ansible介绍
    Gitlab应用——开发人员fetch分支,合并到master主分支申请
    Gitlab应用——系统管理
    Gitlab安装配置管理
  • 原文地址:https://www.cnblogs.com/flyrain/p/excel_vb.html
Copyright © 2011-2022 走看看