使用 Excel 宏选择范围 [英] Range Selection Using Excel Macro

查看:142
本文介绍了使用 Excel 宏选择范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  A      B        C

123455  XXX     99999
123456  XX      100000
123457  XXX     100001
174564  XXXX    100002
184567          100003
194570          100004
204573          100005
214576          100006
224579          100007
                100008

我想编写一个宏来使用 选择范围.+ <向下箭头>

I would like to write a macro for selecting a range using <ctrl> + <down arrow>

流程应该是这样的

  1. 选择单元格 A1
  2. 使用 选择一个范围+ +
  3. 在不取消范围选择的情况下选择单元格 A1(使用 )
  4. ActiveCell.Offset(0, 2).Select
  5. 然后使用 选择从 C1 到 C9 的范围.+ + 然后 + <向上箭头>
  1. Select cell A1
  2. Select a Range with <shift> + <ctrl> + <page down>
  3. Aelect cell A1 without cancelling the range selection (using <ctrl>)
  4. ActiveCell.Offset(0, 2).Select
  5. Then range select from C1 to C9 with <shift> + <ctrl> + <page down> then <shift> + <up arrow>

按照我的示例数据中的这些步骤,在同一行选择了 224579 和 100007,未选择 100008.

Following those steps in my example data, 224579 and 100007 are selected at same row, 100008 is not selected.

我想选择 A1 到 A9 和 C1 到 C9 之间的范围,但我希望宏在不定义 A1 和 A9 等范围的情况下执行此操作,因为该范围可能会像 A1 更改后更改为 A5 一样更改为 A5.所以,我希望宏能够适应并相应地获取数字.

I want to select the range between A1 to A9 also C1 to C9, but I want the macro to do this without defining a range like A1 and A9, because the range will probably change like A1 will change to A5 after some alterations. So, I want the macro to adapt and grab the numbers accordingly.

推荐答案

如果 A1 是活动单元格,这应该可以工作.

This should work if A1 is the active cell.

Union(Range(ActiveCell, ActiveCell.End(xlDown)), Range(ActiveCell.Offset(0, 2), ActiveCell.End(xlDown).Offset(0, 2))).Select

这篇关于使用 Excel 宏选择范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆