The UsedRange property gives us a range that encompasses the cells that have been used to enter data. Step 2 fills the MyRange variable with the UsedRange property of the ActiveSheet object.This variable serves as an incremental counter. The other variable is a Long Integer variable called iCounter. This is an Object variable that defines the target range. The first variable is an object variable called MyRange. We keep doing that same delete for every loop, each time incrementing the counter to the previous column. If the entire column is indeed empty, we remove the column. We then establish a counter that starts at the last column of the used range, checking if the entire column is empty. In this macro, we are using the UsedRange property of the ActiveSheet object to define the range we are working with. If Application.CountA(Columns(iCounter).EntireColumn) = 0 Then 'Step 4: If entire column is empty then delete it. 'Step 3: Start reverse looping through the range.įor iCounter = To 1 Step -1 If you want to delete blank rows, click here. If you find that you are manually searching out and deleting blank columns in your data sets, this simple macro can help automate delete blank columns. Blank columns can often cause problems with formulas.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |