Results 1 to 9 of 9

Delete Columns if Criteria matched.

Threaded View

  1. #1
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Delete Columns if Criteria matched.

    Hey guys, I am again stumped on the syntax for this code. If someone could take a look at it for me I would appreciate it very much.

    I am trying to step through a dynamic range in both columns and rows and delete any columns that have value of "0". In row 1 is the headers for each column.

    I think the problem is with the variable "col"???

    Sub n()
     Dim ws As Worksheet
     Dim LR As Long, i As Long, LC As Long
     Dim col As Range
     
       Set ws = ActiveSheet
       LC = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
       LR = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
         
         For i = LC To 2 Step -1
          Set col = ws.Range(Cells(2, i), Cells(LR, i))
           If col Is Nothing Then
              ws.Columns(i).EntireColumn.Delete Shift:=xlShiftLeft
              
           End If
           Set col = Nothing
        Next i
    
    End Sub
    Thanks
    Last edited by JapanDave; 12-20-2011 at 04:32 AM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1