简体   繁体   English

使用VBA删除“”行

[英]Using VBA to delete “” rows

I have a giant macro. 我有一个巨大的宏。 Because the macro needs to be applied to datasets ranging for 1 to 200,000 rows, there are a lot of steps where I use an =IF formula where one of the outputs is "". 因为宏需要应用于范围为1到200,000行的数据集,所以有很多步骤使用= IF公式,其中输出之一是“”。 Ex: 例如:

=IF(B2="","",CONCATENATE(B2,C2)

These formulas are then autofilled to the bottom of the worksheet. 这些公式然后自动填充到工作表的底部。 Since "" is not a true blank, the files at the end of the output end up being at least 80 mb each, when some could be 10kb. 由于“”不是真正的空白,因此输出末尾的文件每个至少为80 mb,而某些文件可能为10 kb。

I can trim the file again if I export to CSV, change the file extension to txt, open in notepad, and delete all of the rows consisting of nothing but commas, then re-importing the txt file back into Excel, but that requires me to do the extension changing and comma deleting manually, which gets very time consuming. 如果导出到CSV,可以将文件扩展名更改为txt,在记事本中打开,然后删除除逗号以外的所有行,然后将txt文件重新导入到Excel中,则可以再次修剪文件。手动更改扩展名和逗号,这非常耗时。

Does anyone have any tricks (like a substitute for "" that leave behind a true blank after a paste values, or a command that can delete all rows where A = "" that wont take 16 hours to run, evaluating and deleting each of the 1.54 million rows individually)? 是否有人有任何技巧(例如,用“”代替”在粘贴值后留下真正的空白),或可以删除​​A =“”的所有行而无需花费16个小时即可运行的命令,评估并删除每个分别有154万行)?

Something like this should do it in one go: 这样的事情应该一口气做到:

Range("E2:E" & Range("A" & Rows.count).end(xlup).row).formula = "=IF(B2="""","""",CONCATENATE(B2,C2)"

I have made the following assumptions: 我做了以下假设:

You want the formula in column E, change here if not: Range("E2:E" 您需要E列中的公式,如果不需要,请在此处更改: Range("E2:E"

Column A has data all the way down to where you want the formula, change here if not: & Range("A" A列的数据一直到所需的公式,如果没有,请在此处更改: & Range("A"

Excel is smart enough to increment this formula as it posts it to a range, no need to fill down after filling in just one cell. Excel足够聪明,可以在将该公式发布到某个范围时增加该公式,而无需在仅填写一个单元格后进行填写。

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

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