ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How to delete columns with headings but rows are empty (https://www.excelbanter.com/excel-worksheet-functions/257269-how-delete-columns-headings-but-rows-empty.html)

Deb[_4_]

How to delete columns with headings but rows are empty
 
Hi,
I have data where columns have headings but rows are blank. I have
approx 500 rows of data.

ID Student Course 1 Course 2
2 Tom 0
3 Suzie

Thanks for your assistance

Mike H

How to delete columns with headings but rows are empty
 

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Deb" wrote:

Hi,
I have data where columns have headings but rows are blank. I have
approx 500 rows of data.

ID Student Course 1 Course 2
2 Tom 0
3 Suzie

Thanks for your assistance
.


Mike H

How to delete columns with headings but rows are empty
 
Deb,

If I understand correctly we loop through columns and if there are no data
in the column except for the header row we delete the entire column. If
that's correct then try this macro

Sub Del_Cols()
Dim Col As Long
Set sht = Sheets("Sheet1")
For Col = sht.UsedRange.Columns.Count To 1 Step -1
If sht.Cells(Rows.Count, Col).End(xlUp).Row = 1 Then
Columns(Col).EntireColumn.Delete
End If
Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Deb" wrote:

Hi,
I have data where columns have headings but rows are blank. I have
approx 500 rows of data.

ID Student Course 1 Course 2
2 Tom 0
3 Suzie

Thanks for your assistance
.



All times are GMT +1. The time now is 11:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com