Thanks, Rowan!
Rowan Drummond wrote:
> Try:
>
> Sub DelCols()
> Dim Col As Long
> For Col = 31 To 1 Step -1
> With Cells(10, Col)
> If .Value = Empty Then
> .EntireColumn.Delete
> Else
> .EntireColumn.AutoFit
> End If
> End With
> Next Col
> End Sub
>
> Hope this helps
> Rowan
>
> davegb wrote:
> > The following piece of code errors out at the line indicated:
> >
> > Set rTtl = ActiveSheet.Range("A10:AE10")
> >
> >
> > For Each rCell In rTtl
> >
> > rCell.Select
> >
> > If rCell = "" Then
> >
> > rCell.EntireColumn.Delete
> > rCell.Offset(0, -1).Activate<---OBJECT REQUIRED
> >
> > Else: rCell.EntireColumn.AutoFit
> > End If
> > Next
> >
> > Can anyone tell me what it's looking for? I've tried both "activate"
> > and "select", but I get the same error.
> > The program goes across row 10, checking each cell for content. If the
> > cell is blank, it deletes the column. The problem comes when it deletes
> > the column. If the column to the right is also blank, it skips over it
> > when it comes to the "Next" line. I want it to test and, if necessary
> > delete that column.
> > Thanks!
> >
Bookmarks