I would like to create a simple macro, which is something like that:
I have a table with serial numbers and 12 columns measurement result for each serial number. There are a tolerance that has a min. and a max value. I would like to check the results, that if they are in the tolerance field, then set the color of the cell to green.
The table is like this:
and the tolerance values are: min=250
, max=450
.
I wrote this code, but something is not correct.
Sub turesellenorzes()
Dim i As Integer
i = Selection.Value
If (i >= 250 And i <= 450) Then
Selection.Interior.Color = vbGreen
Else: Set Selection.Interior.Color = vbRed
End If
End Sub
Select your Range and call CallTuresellenorzes
:
Option Explicit
Sub callturesellenorzes()
Call turesellenorzes(Selection)
End Sub
Sub turesellenorzes(rng As Range)
Dim i As Integer
Dim cell As Range
For Each cell In rng
If cell >= 250 And cell <= 450 Then
cell.Interior.Color = vbGreen
Else
cell.Interior.Color = vbRed
End If
Next
End Sub
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.