+ Reply to Thread
Results 1 to 10 of 10

macro that deletes certain results

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2008
    Location
    ohio
    Posts
    10

    macro that deletes certain results

    I am making a macro that deletes #N/A's, but i want to add a few things to it
    that should be deleted:

    the phrases "total board", "total metal" and "Item", and any non-text (i.e. any
    number) that appears.

    this is what i have so far:

    Public Sub DeleteStuff()
      Cells.SpecialCells(xlCellTypeFormulas, xlErrors).Delete
    End Sub

    what do i add to meet my specifications? Any help is greatly appreciated.
    Last edited by dfrank; 06-30-2008 at 01:47 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Please read our Forum Rules about thread titles, and then edit your thread title to be descriptive of your problem.

  3. #3
    Registered User
    Join Date
    06-30-2008
    Location
    ohio
    Posts
    10
    For Each cell In Selection
        If cell = ""total board" or cell = "total metal" _
        or IsNumeric(cell)  or cell.HasFormula _
        or IsError(Cell) Then
        cell.Delete
        End If
    Next cell

    I was given this code from a guy somewhere else, but it doesnt work and he dissapeared.

    i basically want to delete the phrases "total board", "total metal" and "Item", and any number.

    also, this is supposed to pertain to the entire worksheet, so i think his 'Selection' part of the code is not correct.

    any help?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Assuming that otherwise does what you want, then maybe like this:
    Sub x()
        Dim cell    As Excel.Range
    
        For Each cell In ActiveSheet.UsedRange
            With cell
                If .Value = "total board" Or _
                   .Value = "total metal" Or _
                   IsNumeric(.Value) Or _
                   .HasFormula _
                   Or IsError(.Value) Then
                    .Delete shift:=xlUp
                End If
            End With
        Next cell
    End Sub

  5. #5
    Registered User
    Join Date
    06-30-2008
    Location
    ohio
    Posts
    10
    appreciate the response, but i get an error doing this. here is what i have:
    \1
    [URL=http://g.imageshack.us/g.php?h=389&i=midstep1hy0.jpg[/URL]

    here is what happens when i use the code provided:

    \1
    \1 do not click second link. it is nothing.
    i get an mismatch error 13.

    any idea on how to fix this?
    Last edited by dfrank; 07-01-2008 at 08:14 AM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Try this. If it doesn't work, please post a workbook with the code in it.
    Sub x()
        Dim cell    As Excel.Range
        
        On Error Resume Next
        ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas).Delete shift:=xlUp
        ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, xlNumbers).Delete shift:=xlUp
        On Error GoTo 0
    
        For Each cell In ActiveSheet.UsedRange
            With cell
                If .Value = "total board" Or _
                   .Value = "total metal" Then
                    .Delete shift:=xlUp
                End If
            End With
        Next cell
    End Sub

+ Reply to Thread

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