Results 1 to 2 of 2

If row got certain value keep it's column but delete the other columns?

Threaded View

  1. #1
    Registered User
    Join Date
    08-17-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    4

    Exclamation If row got certain value keep it's column but delete the other columns?

    Hi, I got several sheets with 200+ columns.

    For every sheet, I want the macro to check row 6 of a column, and if the row contains a certain value, it
    will keep that column but those columns who don't have the value will be deleted.

    I have already tried with this script:

    
    Private Sub CommandButton1_Click()
    
    Dim currentColumn As Integer
        Dim columnHeading As String
    
        For currentColumn = NMBW.UsedRange.Columns.Count To 1 Step -1
    
            columnHeading = NMBW.UsedRange.Cells(6, currentColumn).Value
    
            'CHECK WHETHER TO KEEP THE COLUMN
            Select Case columnHeading
                Case "Planned Date Status PR", "PR Drawing Needed SEU", "Planned Serial Order Date SEU", "Serial Order Placed SEU", "Planned PPAP Appr Date SEU"
                    'Do nothing
                Case Else
                    'Delete if the cell doesn't contain "Homer"
                    If InStr(1, _
                       NMBW.UsedRange.Cells(6, currentColumn).Value, _
                       "Homer", vbBinaryCompare) = 0 Then
    
                        NMBW.Columns(currentColumn).Delete
    
                    End If
            End Select
        Next
    End Sub
    On the fourth line I get error: "Object required"

    Can someone explain why?
    Last edited by Frederic01; 08-17-2016 at 07:58 AM.

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. delete three columns of two grouped columns according to common value of two column
    By shahram_pc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2015, 07:33 PM
  3. Delete all columns if value in row 2 of that column is x?
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-14-2014, 01:47 AM
  4. If column contains certain header, delete column--exempt certain columns
    By kestefon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2013, 04:04 PM
  5. 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
  6. Delete columns where the last row in the column = 0
    By Melyssa18 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2010, 01:09 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