Dodo
04-06-2022, 02:11 PM
[SIZE=3]Hi! I need help with this code. I am only learning VBA and this is still too "complex" for me...
What I want:
For each cell (in a range I defy) of ws1 (blood measurements) IF a cell value in this range is > a specific cell value in ws2 (norm ranges for this blood measurement) AND the value (age of participant) in ws3 is below the value I enter in the code (i.e. 19 years) THEN color the cell (I chose yellow).
(So if in ws1 we start to look at value Z4 of participant 1 then the code has to compare the corresponding age value of this participant in ws3 which is cell D4).
I have to repeat this code then for each column in ws1 and change the references that occur for ws2. I think that I can do that without an issue but the first code part.. I give up for now.
Here is the code I got so far but it doesn't work obviously ��:
Sub KlinChemie()
Dim Cell As Range
Set ws1 = Worksheets("Blood samples")
Set ws2 = Worksheets("Normwerte Blut")
Set ws3 = Worksheets("Alter_berechnet")
For Each Cell In ws1.Range("Z4:Z93")
If (Cell.Value > ws2.Value("I13") And ws3.Value("D4:D93") <= 19) Then
Cell.Interior.Color = 65535
End If
Next Cell
End Sub
See sample file attached. I have been working in VBA "Tabelle7 (Blood samples)" to get this to execute.
Thank you for any help :D
What I want:
For each cell (in a range I defy) of ws1 (blood measurements) IF a cell value in this range is > a specific cell value in ws2 (norm ranges for this blood measurement) AND the value (age of participant) in ws3 is below the value I enter in the code (i.e. 19 years) THEN color the cell (I chose yellow).
(So if in ws1 we start to look at value Z4 of participant 1 then the code has to compare the corresponding age value of this participant in ws3 which is cell D4).
I have to repeat this code then for each column in ws1 and change the references that occur for ws2. I think that I can do that without an issue but the first code part.. I give up for now.
Here is the code I got so far but it doesn't work obviously ��:
Sub KlinChemie()
Dim Cell As Range
Set ws1 = Worksheets("Blood samples")
Set ws2 = Worksheets("Normwerte Blut")
Set ws3 = Worksheets("Alter_berechnet")
For Each Cell In ws1.Range("Z4:Z93")
If (Cell.Value > ws2.Value("I13") And ws3.Value("D4:D93") <= 19) Then
Cell.Interior.Color = 65535
End If
Next Cell
End Sub
See sample file attached. I have been working in VBA "Tabelle7 (Blood samples)" to get this to execute.
Thank you for any help :D