+ Reply to Thread
Results 1 to 9 of 9

Removing Data From Cells if a certian condition exists

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    405

    Removing Data From Cells if a certian condition exists

    This one is kind of strange, but I am certain one of you have a solution.

    I need to change a spreadsheet that has data entered into the wrong place. The attach list of fruit of Apples, Pears and Peaches have the type of that fruit below. Then totals that fruit. There should not be values in the rows next to 1000 Apples, 2000 Pears and 3000 Peaches. I still need the total but need the data removed from (or set to zero) and row that has the prefix of "Total". So in particular, there is a cell in column E that has the prefix of "Total". The first occurrence is E6, "Total 1000 Apples". I need the VBA code to look through the column E and find any occurrence of "Total 1000 Apples" but without the Word "Total", just "1000 Apples", then zero out the data in the columns to the right. Then repeat this for "Total 2000 Pears" zero out data in row "2000 Pears"; and "Total 3000 Peaches" zero out data in row "3000 Peaches".

    The Spreadsheet has a desired result below the top Spreadsheet.

    The spreadsheet always starts in cell E2, the names are only in Column E, the number of rows can be of any length, the name must be an exact match (case sensitive), the name may or may not have numbers, and the data will be in columns F through S to the right of the found name.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by Bobbbo; 03-11-2016 at 03:42 PM. Reason: Mark it solved

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Removing Data From Cells if a certian condition exists

    If the layout remains the same, filter is the best code.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    405

    Re: Removing Data From Cells if a certian condition exists

    Not quit sure what you mean. Would that be a formula?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Removing Data From Cells if a certian condition exists

    Remove the output data from the sheet and run the code. I have already run the code and see the result.

  5. #5
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    405

    Re: Removing Data From Cells if a certian condition exists

    AB33, I looked at the code again and it will not do what I am asking for as your code has the names ("1000 Apples", "2000 Pears", "3000 Peaches") which I will not know. These names could be anything, I just need it to find the same name for any account that starts with "Total".

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Removing Data From Cells if a certian condition exists

    from the excel main menu, choose DATA. Now select some columns that you would like to filter. Then from the DATA menu, select Filter (in the middle). Then pick one of the arrows next to column and filter your data.

  7. #7
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Removing Data From Cells if a certian condition exists

    a vba solution

    Sub removeSubTotals()
    Dim startRow As Long, lastRow As Long, lastCol As Long
    Dim searchStr As String
    
    With Sheets("Sheet1")
        startRow = 2
        lastRow = .Cells(startRow, 5).End(xlDown).Row
        lastCol = .Cells(startRow, 5).End(xlToRight).Column
    
    For r = lastRow To startRow Step -1
            If Left(.Cells(r, 5).Value, 5) = "Total" Then
                searchStr = Mid(.Cells(r, 5).Value, 7)  '= text to match
            End If
            
            If .Cells(r, 5).Value = searchStr Then
                For c = 6 To lastCol
                Cells(r, c).Value = 0
                Next c
            End If
    Next r
    End With
    End Sub

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Removing Data From Cells if a certian condition exists

    For the data provided.
    Sub test()
        Dim x, e
        With Range("e1").CurrentRegion
            With .Columns(1)
                x = Filter(Evaluate("transpose(if(left(" & .Address & ",6)=""Total "",mid(" & _
                        .Address & ",7,100),char(2)))"), Chr(2), 0)
                x = Application.Match(x, .Cells, 0)
            End With
            For Each e In x
                .Rows(e).Offset(, 1).Resize(, .Columns.Count - 1).Value = 0
            Next
        End With
    End Sub

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Removing Data From Cells if a certian condition exists

    If it starts with "Total", how come then rows which have total are not zeros? Try then the adjusted code.
    Attached Files Attached Files

+ 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. how do I sum cells if a condition exists?
    By TheVolkinator in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-14-2015, 04:53 PM
  2. [SOLVED] Hide cell if certian cells equal a certian criteria
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2014, 09:39 AM
  3. Lock certain cells only if condition exists in another cell
    By finjim in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2013, 11:47 PM
  4. Caluculation for adding up cells if the cells are a certian colour
    By beaker28 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-22-2013, 07:48 AM
  5. Anyway to auto Capitalization on certian cells?
    By jakweeze in forum Excel General
    Replies: 12
    Last Post: 05-06-2011, 07:41 PM
  6. Counting cells of a certian value .....
    By Carl1966 in forum Excel General
    Replies: 5
    Last Post: 06-18-2009, 09:26 AM
  7. [SOLVED] Count cells for certian data
    By andespoint in forum Excel General
    Replies: 3
    Last Post: 06-27-2006, 09:10 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