+ Reply to Thread
Results 1 to 7 of 7

Clear all cells when the are not between 0.90-0.95

Hybrid View

FvdF Clear all cells when the are... 06-08-2023, 05:37 AM
Sam Capricci Re: Clear all cells when the... 06-08-2023, 07:13 AM
wk9128 Re: Clear all cells when the... 06-08-2023, 08:15 AM
FvdF Re: Clear all cells when the... 06-08-2023, 08:58 AM
Sam Capricci Re: Clear all cells when the... 06-08-2023, 09:02 AM
Sam Capricci Re: Clear all cells when the... 06-08-2023, 09:06 AM
leelnich Re: Clear all cells when the... 06-08-2023, 09:55 AM
  1. #1
    Forum Contributor
    Join Date
    03-22-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016-2019, LTSC Pro Plus 2021, Office365
    Posts
    149

    Clear all cells when the are not between 0.90-0.95

    I need a formula or vba script that will clear all cells in column "C,E,G,I" that are not between 0.90-0.95.

    Who can help me with this?

    Kind Regards,

    FvdF
    Attached Files Attached Files

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.95 for Mac MS 365
    Posts
    8,682

    Re: Clear all cells when the are not between 0.90-0.95

    formulas can't clear cells, you could write a formula in another area that would indicate which cells to clear or a formula that returns a blank if the cell is not between those parameters and the numbers that are within those parameters, then copy over those values and paste them into the same cells. Is that something you can work with? otherwise you will need VBA.

    this would be the formula version... =IF(OR(C3<0.9,C3>0.95),"",C3) then copy and paste special the results over the column C, repeat for E, G and I.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Expert wk9128's Avatar
    Join Date
    08-15-2020
    Location
    China Shanghai
    MS-Off Ver
    365 V2502 and WPS V2024(12.1.0.18543)
    Posts
    3,866

    Re: Clear all cells when the are not between 0.90-0.95

    pls try this code

    Sub wkClearCells()
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Dim ws As Worksheet
        Dim rng As Range
        Dim cell As Range
        Dim cellsToClear As Range
        Set ws = ThisWorkbook.Worksheets("Blad1")
        Set rng = ws.Range("C3:C11,E3:E11,G3:G11,I3:I11")
        For Each cell In rng
            If Not (cell.Value >= 0.9 And cell.Value <= 0.95) Then
                If cellsToClear Is Nothing Then
                    Set cellsToClear = cell
                Else
                    Set cellsToClear = Union(cellsToClear, cell)
                End If
            End If
        Next cell
        If Not cellsToClear Is Nothing Then
            cellsToClear.ClearContents
        End If
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
    End Sub
    Last edited by wk9128; 06-08-2023 at 08:22 AM.

  4. #4
    Forum Contributor
    Join Date
    03-22-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016-2019, LTSC Pro Plus 2021, Office365
    Posts
    149

    Re: Clear all cells when the are not between 0.90-0.95

    Hoi wk9128

    This works fine as I can see now. Still one question can you change this range with rows C,E,F,I
    These rows are feeding every day with new cells.

    Kind regards
    FvdF

  5. #5
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.95 for Mac MS 365
    Posts
    8,682

    Re: Clear all cells when the are not between 0.90-0.95

    well I did not write the code so the credit goes to wk9128 but I would assume you'd make the change here...

    PHP Code: 
    Sub wkClearCells()
        
    Application.ScreenUpdating False
        Application
    .Calculation xlCalculationManual
        Dim ws 
    As Worksheet
        Dim rng 
    As Range
        Dim cell 
    As Range
        Dim cellsToClear 
    As Range
        Set ws 
    ThisWorkbook.Worksheets("Blad1")
        
    Set rng ws.Range("C3:C11,E3:E11,F3:F11,I3:I11")
        For 
    Each cell In rng
            
    If Not (cell.Value >= 0.9 And cell.Value <= 0.95Then
                
    If cellsToClear Is Nothing Then
                    Set cellsToClear 
    cell
                
    Else
                    
    Set cellsToClear Union(cellsToClearcell)
                
    End If
            
    End If
        
    Next cell
        
    If Not cellsToClear Is Nothing Then
            cellsToClear
    .ClearContents
        End 
    If
        
    Application.ScreenUpdating True
        Application
    .Calculation xlCalculationAutomatic
    End Sub 
    Last edited by Sam Capricci; 06-08-2023 at 09:05 AM.

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.95 for Mac MS 365
    Posts
    8,682

    Re: Clear all cells when the are not between 0.90-0.95

    note to admin/moderators, I tried to use html settings but it wouldn't show properly - sorry.

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Clear all cells when the are not between 0.90-0.95

    Or this. You can adjust columns in the red line:
    Sub FilterVals01()
    Dim i As Long, k as Long, COLS As Variant
    
    Sheets("Blad1").Activate
    If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
    
    COLS = Split("C,E,G,I", ",")
    
    With Cells(1, 1).CurrentRegion.Offset(1)
      For i = 0 To UBound(COLS)
        k = Columns(COLS(i)).Column
        .AutoFilter k, "<.90", xlOr, ">.95"
        .Offset(1).Columns(k).SpecialCells(xlVisible).ClearContents
        .AutoFilter k
      Next
    End With
    
    ActiveSheet.AutoFilterMode = False
    
    End Sub
    Last edited by leelnich; 06-08-2023 at 10:11 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

+ 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] Sum constant 52 previous cells in one column ignoring clear cells
    By ip74 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-22-2022, 11:53 AM
  2. Replies: 1
    Last Post: 09-24-2021, 10:42 AM
  3. vba CODE TO FILTER OUT BLANK CELLS/GHOST CELLS and clear them
    By r1shabharora in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2019, 06:01 PM
  4. VBA to Clear 1 Cell and Clear other cells Formula only
    By oneblondebrow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2017, 12:56 PM
  5. [SOLVED] Macro to clear cells in range & move up if certain cells meet criteria
    By samder68 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2016, 10:52 PM
  6. [SOLVED] Clear Cells Not Clear
    By prjt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2015, 03:23 PM
  7. Clear contents of cells that do not contain specific text, sort cells that do
    By feckless.lout in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 01:41 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