Need help deleting empty columns not cells

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,079
Office Version
  1. 365
Platform
  1. Windows
Hi I need help deleting Columns that have empty data in whole column. Not if there is empty cells. example if I select Column C D and E because all the way down that line has no data. Then I want to delete them so it shifts to the left.

I tried Find & Select Co to special then blanks and delete to try to record a code, but it doesn't do what I need it to do.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this:
Code:
Sub MyDeleteColumns()

    Dim Cols As Variant
    Dim i As Long
    Dim mycol As String
    Dim myRow As Long
    
'   List columns to check, in reverse order
    Cols = Array("E", "D", "C")

'   Loop through each column
    For i = LBound(Cols) To UBound(Cols)
'       Capture column letter
        mycol = Cols(i)
'       Check value in first row of current column
        If Cells(1, mycol) = "" Then
'           Go down, and see if it at last row and it is empty
            myRow = Cells(1, mycol).End(xlDown).Row
            If myRow = Rows.Count And Cells(myRow, mycol) = "" Then
                Columns(mycol).Delete
            End If
        End If
    Next i
            
End Sub
 
Upvote 0
ok gonna try this in my code now. Will let you know thank you
 
Upvote 0
Something like this might work for you:
Code:
Sub DelBlankCol()
    myCol = "G"
    lr = Cells(Rows.Count, myCol).End(xlUp).Row
    If lr = 1 And IsEmpty(Range(myCol & lr).Value) Then
        Range(myCol & ":" & myCol).EntireColumn.Delete
    End If
    
End Sub

You'd have to tailor it to select the columns that you are interested in...

HTH,
~ Jim
 
Upvote 0
Here is a little shorter version of the first code I posted:
Code:
Sub MyDeleteColumns()

    Dim Cols As Variant
    Dim i As Long
    Dim myCol As String

'   List columns to check, in reverse order
    Cols = Array("E", "D", "C")

'   Loop through each column
    For i = LBound(Cols) To UBound(Cols)
'       Capture column letter
        myCol = Cols(i)
        If Columns(myCol).SpecialCells(xlCellTypeBlanks).Cells.Count = Rows.Count Then
            Columns(myCol).Delete
        End If
    Next i
    
End Sub
 
Last edited:
Upvote 0
Joe I was giving an example on those columns. E D C. I'm trying for the code to locate the empty rows lets say if it was E D & C and then delete those empty rows that have absolutely no data thanks
 
Upvote 0
I am sorry, but based on what you originally said here:
Hi I need help deleting Columns that have empty data in whole column. Not if there is empty cells. example if I select Column C D and E because all the way down that line has no data. Then I want to delete them so it shifts to the left.
and then this:
I'm trying for the code to locate the empty rows lets say if it was E D & C and then delete those empty rows that have absolutely no data thanks
It is very confusing and unclear to me what you are asking.

Perhaps if you could paste a data sample, and then walk us through what should happen it that example, it will be clearer.
 
Upvote 0
Ok see if this helps. Sorry for any confusion. As you see in D & B there is no data so I need to delete those rows.


Excel 2016 (Windows) 32 bit
A
B
C
D
E
1
john
2
mike
3
4
JJJay
5
6
7
8
9
10
Jay
11

<tbody>
</tbody>
Sheet: Sheet1

<tbody>
</tbody>
 
Last edited:
Upvote 0
I think part of the problem is you are mixing nomenclature here. B and D are columns, not rows. So I am not sure if you want to delete columns or rows.
So what exactly do you want to delete in that scenario?
Maybe post what your expected result of this example should look like.
 
Upvote 0
Yeah I meant columns sorry not rows. Its Friday thinking to fast and typing. Not thinking right.

Results:

Excel 2016 (Windows) 32 bit
A
B
C
1
John
2
mike
3
4
JJJay
5
6
7
8
9
10
Jay
11
12
13
Sheet: Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,176
Members
448,948
Latest member
spamiki

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