您的位置:首页 > 编程语言 > VB

【Excel VBA】properties & methods of RANGE

2019-03-23 10:26 218 查看


SpecialCells:
find special cells 指定类型查找

1. To find the end of a range

  1. find the last row
  • 适用于range中间没有空行,End(xlDown)相当于ctrl + down,直接拉到Range最底下
  • Row => get the number of row
  1. another way to find the last row

    从整个表的最后一行jump back
    Rows.Count => find how many rows in the worksheet

  2. find next empty cell

  3. find the last column

  4. current region

    current region的地址
    current region有多少行

  5. special cells

    special cells有很多种选项:

2. Copy & paste method

  1. copy everything

    Range(要复制的区域).copy.range(要粘贴的区域)

  2. special copy

    先copy当前region
    和special cell一样,可以选要paste哪些内容

  3. resize

    先offset一行,就是把header去掉,但是整个表的row也要减去一行

  4. Cuting mode = false
    copy和paste分开时,原区域仍然会被选中
    copy mode例子

3. reference worksheet


为什么不能用active sheet?

因为在VBA中,active sheet被当作一个object, 但又不是特定的object, 所以没有intelliSense

方法1:

新建一个variable (sh),将sh归入Worksheet类,然后再赋值为active sheet

方法2:

如果要指定特定的表,可以用表名,最好用code name(在VBE中才能看到,不会被随意修改)

code name可以在properties中修改

4. Reference workbook

debug.print 将VBA在immediate窗口运行,用于调试

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: