简体   繁体   中英

VBA for filtering cells in a row based on another cell value in the same row

I have an excel sheet with numbers in each cell. I want to eliminate the cells containing values which are larger than a specific value, different for each row, for example in the picture

在此处输入图片说明

I want to eliminate all the cells in a certain row that has values more than the BL cell.

Not sure the exact context in which this is being used, So possibly some conditional formatting would be more stable?

Also not sure what you meant by "Eliminate" so the following code just turns the cell red.

anyway, hopefully this code will help you get started :)

Sub Cell_Vaue_Check()
    Dim row As Excel.Range
    Dim cel As Excel.Range
    For Each row In Sheets("Sheet1").Range("A1:C5").Rows '<<- Replace "Sheets("Sheet1").Range("A1:C5")" with the Sheet and Range you want to check
        For Each cel In row.Cells
            If cel.Value > Range("E" & cel.row).Value Then '<<- Replace "E" with the Column in which the check value is located
                cel.Interior.Color = RGB(288, 0, 0) '<<- This line turns the cell Red. Replace it with whatever code you want depending on what "eliminate" means to you
            End If
        Next
    Next
    Set row = Nothing
    Set cel = Nothing
End Sub

If Anybody has any improvements please feel free to Add!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM