本文介绍了我需要在VBA中对activecell.offset进行解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解某些VBA代码方面有些困难.我没问题

I have some difficulty in understanding some VBA code. I have no problem with

activecell.offset(1,1).select

但是,我有问题

activecell.offset(1,1).range("A1").select 

AND

ActiveCell.Offset(0, 3).Columns("A:A").EntireColumn.Select

为什么那里有一个.range("A1")?为什么那里有一个.columns?我读了另一篇文章,说这些东西不是必需的.但是我使用相同的格式编写了一些代码,将.range("A1")替换为其他范围,并产生了不同的结果.你能给我解释一下这些事吗?我的意思是偏移后的.range("A1").我从试图理解的其他人那里继承了代码.

Why is there a .range("A1") there? Why is there a .columns there? I read some other post saying that these things are not necessary. But I wrote some code using the same format, replacing .range("A1") with some other range and yielded a different results. Could you please explain these things to me? I mean the .range("A1") after offset. I inherited the code from someone else trying to understand.

推荐答案

即使您只选择一个单元格,在记录宏时,Excel通常也会添加.range("A1")部分.本质上,"A1"是指.activecell.offset位置左上角的单元格.因此,例如,如果您将其更改为:

The .range("A1") part you usually find added by Excel when you record a macro, even if you only select one cell. Essentially "A1" refers to the cell in the top-left-hand corner of the .activecell.offset position. So, if for example you changed this to:

ActiveCell.Offset(0, 1).Range("A1:A3").Select

活动单元格将成为从起始单元格开始为0行,+ 1列的单元格,然后选择1列和3行大小的区域,但此处A列和3行是对activecell的相对引用.位置,而不是参考工作表的A列第1-3行.玩"A1:A3",看看我的意思.

The active cell would become the cell which is 0 rows, +1 column from the starting cell, then select an area 1 column and 3 rows in size, but here column A and rows 3 are RELATIVE references to the activecell.offset position, rather than refering to the worksheets column A, rows 1-3. Play around with "A1:A3" to see what I mean.

代码可能更简单,只需说一遍

The code might be simpler and just say

ActiveCell.Offset(0, 1).Select

这将是完全有效的,但是此代码不允许您选择多个单元格.为此,您需要使用RANGE.

which would be perfectly valid, but this code does not allow you to SELECT more than one cell. To do that, you need to use RANGE.

这篇关于我需要在VBA中对activecell.offset进行解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:24