How to delete columns with headings but rows are empty

  • Thread starter Thread starter Deb
  • Start date Start date
D

Deb

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

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
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.
 
Back
Top