Removing a large number of empty columns.

Elihue

New Member
Joined
Aug 16, 2016
Messages
21
Hello!

First time poster here. I am an excel novice. Long story short, I have a large .CSV spreadsheet where I need to automatically remove unused/blank columns. However the columns that end up empty will be different every time. I have tried using Power-Query to solve this issue but I only see a button for "remove blank rows" there does not seem to be a button for "remove blank columns". I tried "transforming" the data, then hitting the "remove blank rows" button and then "transforming" the data back. This works, but I lose my header names and I cannot have that. So I was wondering if anyone here could point me in the right direction of a quick and simple solution. Is there another power BI tool or piece of software that will support this function? Is there a way to do this in PQ that I'm just not seeing? By the way I am aware that columns can be removed manually but sometimes I end up with hundreds of different blank columns throughout my data that all need to be removed in a timely fashion. Any help would be greatly appreciated.

Thanks.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi Matt!

I seem to have found a solution to my problem. The data fields in the columns themselves would always be blank, but they would still have headers. For some reason, sense the columns had that little bit a header data none of the other easy methods for automatically removing blank columns that I found floating around the internet worked. They would see the header data and skip over all the blank columns thinking those columns were not blank. I finally found a solution! It's a random macro I found on a random website. I don't really know anything about macros because I am an excel novice. But here it is so you guys can check it out.

<code>Sub DeleteEmptyColumns()

Dim lastColumn As Integer
Dim lastRow As Integer
Dim i As Integer
Dim r As Range

Set r = ActiveSheet.Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, SearchDirection:=xlPrevious)

If Not r Is Nothing Then

lastColumn = r.Column

For i = lastColumn To 1 Step -1

Set r = ActiveSheet.Columns(i).Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious)

If r Is Nothing Then
ActiveSheet.Columns(i).Delete
Else
If r.Row = 1 Then
ActiveSheet.Columns(i).Delete
End If
End If

Next i

End If

End Sub

So if your like me and have large .CSV spreadsheets with random columns that have headers, but otherwise are blank, this might work for you. Now I just need to figure out PowerPivot.:confused: So I can make the data as easy to read as possible with pivot tables and slicers.
</code>
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top