+ Reply to Thread
Results 1 to 6 of 6

Delete columns

Hybrid View

sprit36 Delete columns 07-11-2017, 07:40 AM
PFDave Re: Delete columns 07-11-2017, 08:34 AM
JOHN H. DAVIS Re: Delete columns 07-11-2017, 09:27 AM
sprit36 Re: Delete columns 07-11-2017, 09:49 AM
sprit36 Re: Delete columns 07-11-2017, 06:23 PM
JOHN H. DAVIS Re: Delete columns 07-12-2017, 02:22 PM
  1. #1
    Forum Contributor
    Join Date
    05-16-2017
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    103

    Delete columns

    Good morning, I do not know how to do it so that when the column is called MONTH it erases it completely, if the column or has any data, also it must erase it, if the column has zeros in all the cells also erase it. Should be deleted by those criteria since they are not always in the same column. Thank you.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor PFDave's Avatar
    Join Date
    05-17-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2013
    Posts
    1,067

    Re: Delete columns

    Hi,

    This Code will check those 3 criteria

    
    Sub Test()
    
    Dim LR As Long, LC As Long, x As Integer, WF As WorksheetFunction
    
    LR = ActiveSheet.UsedRange.Rows.Count
    LC = ActiveSheet.UsedRange.Columns.Count
    Set WF = Application.WorksheetFunction
    
    For x = LC To 1 Step -1
        If Cells(1, x) = "MONTH" Then
        Columns(x).Delete
        Else
            If WF.CountBlank(Range(Cells(1, x), Cells(LR, x))) = LR Then
            Columns(x).Delete
            Else
                If WF.Sum(Range(Cells(1, x), Cells(LR, x))) = 0 Then
                Columns(x).Delete
                End If
            End If
        End If
        
    Next x
    
    End Sub
    Please do add reputation where you see fit, it's nice to be nice and we all enjoy a pat on the back

    Please also mark your thread as solved once it has been.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Delete columns

    Maybe:

    Sub sprit36()
    Dim x As Long, i As Long, y As Long
    x = ActiveSheet.UsedRange.Columns.Count
    For i = x To 1 Step -1
    y = Cells(Rows.Count, i).End(3).row
    Cells(y + 1, i).Formula = "=SUM(" & Range(Cells(2, i), Cells(y, i)).Address & ")"
        If Cells(1, i) = "MONTH" Then Columns(i).Delete
        If Cells(y + 1, i).Value = 0 Then Columns(i).Delete
    Next i
    End Sub

  4. #4
    Forum Contributor
    Join Date
    05-16-2017
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    103

    Re: Delete columns

    Thank you very much, the two work perfectly. One last question if you would like before deleting a cell to change its name, cell A1, instead of DAY, put DAYS. What change would I have to make? Thank you.

  5. #5
    Forum Contributor
    Join Date
    05-16-2017
    Location
    Spain
    MS-Off Ver
    2010
    Posts
    103

    Re: Delete columns

    I have already solved. Thanks for your help. regards

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Delete columns

    You're welcome. Glad to help out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macros - Delete Columns, Cut & Paste Columns then Sorted by Column
    By M12NIX in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-17-2015, 10:49 AM
  2. vb script to find specific names in columns and delete the other columns
    By mac7988 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2015, 09:03 AM
  3. Delete 1 to 8 rows. Do text to columns to specific columns.
    By niceblue in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2013, 10:53 AM
  4. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  5. Delete all blank columns !!!DELETE!!! [*DUPLICATE*]
    By Storm08 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2012, 05:26 AM
  6. Delete & Merge Columns,Delete Rows with filter, etc
    By traderindia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2009, 02:12 AM
  7. Delete multiple columns by column name no criteria need, just delete them
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2009, 10:40 AM

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