简体   繁体   中英

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 "". 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.

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.

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)?

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"

Column A has data all the way down to where you want the formula, change here if not: & 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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