简体   繁体   English

复制并粘贴公式,直到在Excel-VBA中满足条件

[英]Copy and Paste formula until a condition is met in Excel-VBA

I want to create a macro that copies the top row of formulas and continue dropping it down the worksheet until one of the formulas in the previous row returns a blank. 我想创建一个宏来复制公式的第一行,然后继续将其拖放到工作表中,直到上一行中的公式之一返回空白为止。

Here is my code: 这是我的代码:

Range("C8:V8").Select
Selection.Copy
Do
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveSheet.Past
Loop Until ActiveCell.offest(-1, 15) = ""

Any thoughts on why I keep getting an error? 关于为什么我总是出错的任何想法?

If you want to check all of the cells for a possible blank, you can use the VBA version of COUNTBLANK for that. 如果要检查所有单元格是否有空白,可以为此使用COUNTBLANK的VBA版本。

Loop Until Application.CountBlank(ActiveCell.Offset(-1).Resize(,15)) > 0

The call to Resize is needed to get a range that includes all of the cells for all 15 columns. 需要调用Resize才能获得一个范围,其中包括所有15列的所有单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM