Hi, im a relative noob to VBA. I am trying to compare two or more cells within a column. For example is any cell in Column A < 7 and is any of the other cells in Column A > 10.
If so I'd like to print a message. The thing is I have a code to do this but it is very long:
e.g
but as you can see it can be very long when there are lots of cells in the column to compare. What I would like is a way of doing the same calculations but with a much shorter code.
Any help would be much appreciated.
If so I'd like to print a message. The thing is I have a code to do this but it is very long:
e.g
Code:
If Range("H5").Value < 10.5 And Range("H5").Value > 6 And Range("H6").Value > 15 And Range("H6").Value < 20 Then
Sheet1.Cells(5, 9) = "matching"
ElseIf Range("H5").Value < 10.5 And Range("H5").Value > 6 And Range("H7").Value > 15 And Range("H7").Value < 20 Then
Sheet1.Cells(5, 9) = "matching"
ElseIf Range("H5").Value < 10.5 And Range("H5").Value > 6 And Range("H8").Value > 15 And Range("H8").Value < 20 Then
Sheet1.Cells(5, 9) = "matching"
ElseIf Range("H5").Value < 10.5 And Range("H5").Value > 6 And Range("H9").Value > 15 And Range("H9").Value < 20 Then
Sheet1.Cells(5, 9) = "matching"
ElseIf Range("H5").Value < 10.5 And Range("H5").Value > 6 And Range("H10").Value > 15 And Range("H10").Value < 20 Then
Sheet1.Cells(5, 9) = "matching"
Else
Sheet1.Cells(5, 9) = ""
End If
If Range("H6").Value < 10.5 And Range("H6").Value > 6 And Range("H5").Value > 15 And Range("H5").Value < 20 Then
Sheet1.Cells(6, 9) = "matching"
ElseIf Range("H6").Value < 10.5 And Range("H6").Value > 6 And Range("H7").Value >15 And Range("H7").Value < 20 Then
Sheet1.Cells(6, 9) = "matching"
ElseIf Range("H6").Value < 10.5 And Range("H6").Value > 6 And Range("H8").Value >15 And Range("H8").Value < 20 Then
Sheet1.Cells(6, 9) = "matching"
ElseIf Range("H6").Value < 10.5 And Range("H6").Value > 6 And Range("H9").Value > 15 And Range("H9").Value < 20 Then
Sheet1.Cells(6, 9) = "matching"
ElseIf Range("H6").Value < 10.5 And Range("H6").Value > 6 And Range("H10").Value > 15 And Range("H10").Value < 20 Then
Sheet1.Cells(6, 9) = "matching"
Else
Sheet1.Cells(6, 9) = ""
End If
If Range("H7").Value < 10.5 And Range("H7").Value > 6 And Range("H5").Value > 15 And Range("H5").Value < 20 Then
Sheet1.Cells(7, 9) = "matching"
ElseIf Range("H7").Value < 10.5 And Range("H7").Value > 6 And Range("H6").Value > 15 And Range("H6").Value < 20 Then
Sheet1.Cells(7, 9) = "matching"
ElseIf Range("H7").Value < 10.5 And Range("H7").Value > 6 And Range("H8").Value > 15 And Range("H8").Value < 20 Then
Sheet1.Cells(7, 9) = "matching"
ElseIf Range("H7").Value < 10.5 And Range("H7").Value > 6 And Range("H9").Value > 15 And Range("H9").Value < 20 Then
Sheet1.Cells(7, 9) = "matching"
ElseIf Range("H7").Value < 10.5 And Range("H7").Value > 6 And Range("H10").Value > 15 And Range("H10").Value < 20 Then
Sheet1.Cells(7, 9) = "matching"
Else
Sheet1.Cells(7, 9) = ""
End If
If Range("H8").Value < 10.5 And Range("H8").Value > 6 And Range("H5").Value > 15 And Range("H5").Value < 20 Then
Sheet1.Cells(8, 9) = "matching"
ElseIf Range("H8").Value < 10.5 And Range("H8").Value > 6 And Range("H6").Value > 15 And Range("H6").Value < 20 Then
Sheet1.Cells(8, 9) = "matching"
ElseIf Range("H8").Value < 10.5 And Range("H8").Value > 6 And Range("H7").Value >15 And Range("H7").Value < 20 Then
Sheet1.Cells(8, 9) = "matching"
ElseIf Range("H8").Value < 10.5 And Range("H8").Value > 6 And Range("H9").Value > 15 And Range("H9").Value < 20 Then
Sheet1.Cells(8, 9) = "matching"
ElseIf Range("H8").Value < 10.5 And Range("H8").Value > 6 And Range("H10").Value > 15 And Range("H10").Value < 20 Then
Sheet1.Cells(8, 9) = "matching"
Else
Sheet1.Cells(8, 9) = ""
End If
but as you can see it can be very long when there are lots of cells in the column to compare. What I would like is a way of doing the same calculations but with a much shorter code.
Any help would be much appreciated.