BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
I am using the following code to delete all empty columns in a specific range:
The above code works fine. I need to perform the same operation on another data set that is two columns over from the last column in the original data set. So if the last column first set of data ends at column D, I have a blank column in E (to create some separation between the two tables), and then the new data set starting in Column F.
The problem is that the code above is also deleting that empty column in between the first and second data sets.
Is there any easy change I can make to the above code to keep that separating empty column but delete the rest?
VBA Code:
Do Until LastColumn = 0
If WorksheetFunction.CountA(Columns(LastColumn)) = 0 Then
Columns(LastColumn).Delete
End If
LastColumn = LastColumn - 1
Loop
The above code works fine. I need to perform the same operation on another data set that is two columns over from the last column in the original data set. So if the last column first set of data ends at column D, I have a blank column in E (to create some separation between the two tables), and then the new data set starting in Column F.
The problem is that the code above is also deleting that empty column in between the first and second data sets.
Is there any easy change I can make to the above code to keep that separating empty column but delete the rest?