zoukankan      html  css  js  c++  java
  • vba 对Excel 表格的操作

    vba 基础语法:

    变量的定义:

    变量:Dim   xxdim xx,mm    dim  xxx  as string

    定义常量 :const x  

    数据类型

    dim x

    x = array("xx","yy")

     循环

    for i = 1 to 

    嘻嘻嘻

    next

    for each j  in xxx

    xxxx

    next

    do while xxx

    xxx

    exit do 跳出循环

    loop

    if 判断

    if  xxx  then

    end if 

    if xxx  then  else  end if 

    函数调用 

    sub test(x)

    xxxx

    end sub 

    test  x

    function demo()

    xx

    end function

    demo()

    异常处理:

    on error goto error_miaoshu

    xxxxx

    error_miaoshu     异常处理直接跳到指定的地方

    on error resume next   遇到报错,直接走下一行

    excle

    根据表名获取对象:  set  sheet_obj = sheets("表名")   sheet_obj.cells(1,1) = 8

    当列的有效行数: max = sheet_obj.cells(rows.count,"G").end(xlup).row  

    当行有效列数; ma小 = sheet_obj.cells(5,columns.count).end(xlup).column

    整个表有效行数:sheet_obj.usedrange.rows.count

    整个表有效列数:sheet_obj.usedrange.columns.count

    一列 数据对象:dim arr as variant

    arr = range("A5:A100")

  • 相关阅读:
    CSS教程:div垂直居中的N种方法
    .NET中Flags枚举的使用
    C# 两种方法实现HTTP协议迷你服务器
    百度面试题:求绝对值最小的数
    单点登录
    三范式
    hibernate cascade
    debugview trace 调试
    面向模式的软件体系结构
    待研究
  • 原文地址:https://www.cnblogs.com/LMTlmt/p/13280418.html
Copyright © 2011-2022 走看看