Hi all,
I was hoping to find an answer about deleting all of the blank columns in a range by clicking a button.
i have tried firefly's code on another thread:
But didn't have any luck is that the right kinda code or not?Sub Del_Col() Dim i As Long For i = Cells(1,Columns.Count).End(xlToLeft).Column to 1 Step -1 If Cells(1,i).EntireColumn.Find(What:="*",LookAt:=xlWhole, Searchdirection:=xlPrevious, SearchOrder:=xlByRows).Row=1 Then _ Cells(1,i).EntireColumn.Delete Next i End Sub
Thanks,
Storm08
Last edited by Storm08; 01-24-2012 at 08:34 AM.
Try This:
Sub DelUnusedCols() Dim i As Long, c As Long, r As Long, n As Long Dim oSht As Worksheet Dim bDel As Boolean Set oSht = ThisWorkbook.ActiveSheet c = oSht.Cells.SpecialCells(xlCellTypeLastCell).Column r = oSht.Cells.SpecialCells(xlCellTypeLastCell).Row For i = c To 1 Step -1 bDel = True For n = 1 To r If Cells(n, i) <> "" Then bDel = False Exit For End If Next If bDel = True Then oSht.Columns(i).EntireColumn.Delete Next End Sub
Regards,
Khaled Elshaer
www.BIMcentre.com
Remember To Do the Following....
- Thank those who have helped you by clicking the Star below their post.
- Mark your post SOLVED if it has been answered satisfactorily:
- Select Thread Tools (on top of your 1st post)
- Select Mark this thread as Solved
awesome, cheers! works greatalso, would there be a function to undo macros? e.g - so the user could undo the blank column they have just deleted?
Ill change the name f the thread so it's more helpful to others if there's an answer?
Thank you!![]()
sub snb() for each clm in usedrange.columns if clm.specialcells(4).count=clm.cells.count then clm.delete next next
Awesome, cheers snb, you've been a big help!![]()
Storm, Please mark the thread as SOLVED
Regards,
Khaled Elshaer
www.BIMcentre.com
Remember To Do the Following....
- Thank those who have helped you by clicking the Star below their post.
- Mark your post SOLVED if it has been answered satisfactorily:
- Select Thread Tools (on top of your 1st post)
- Select Mark this thread as Solved
Sorry! still getting used to the forum rules![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks