Hi, Vikas_Gautam,
place an x in 2 cells like C and D and the value in C will stay after your suggestion. Deletion sould either be done from the bottom to the top (or the right to lthe left) or by using a range object and deleting the big range at the end:
![]()
Sub SampleOne() Dim cell As Range Dim rngBig As Range For Each cell In Range("A2:" & Cells(2, Columns.Count).End(xlToLeft).Address(False, False)) If cell.Value = "x" Then If rngBig Is Nothing Then Set rngBig = cell Else Set rngBig = Union(rngBig, cell) End If End If Next cell If Not rngBig Is Nothing Then rngBig.EntireColumn.Delete Set rngBig = Nothing End If End Sub[ Edit ]And of course ClearContents will work properly while Delete won´t..[ /Edit]![]()
Sub SampleTwo() Dim lngCol As Long For lngCol = Cells(2, Columns.Count).End(xlToLeft).Column To 1 Step -1 With Cells(2, lngCol) If .Value = "x" Then .EntireColumn.Delete End If End With Next lngCol End Sub
Ciao,
Holger











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks