Hi!
I know there has to be a more efficient way to write this and am looking for some help with my code to be cleaner and more dynamic.
For a worksheet named Q1,
My code currently works but is ugly and inefficient:
>>> use code - tags <<<
Thank you for any help!
I know there has to be a more efficient way to write this and am looking for some help with my code to be cleaner and more dynamic.
For a worksheet named Q1,
- In cell C19, I will have an integer (3-8)
- I want cell C21 to start as an integer based off C19:
- "4" if C19 >=4
- the value in C19 if C19<4
- Next, I want cell C21 to adjust down from the initial setpoint based on the logic between cells C13 and Q35 as follows:
- C21 starts at an initial value above
- If C13 is 0, remain at the initial value
- If C13 is not 0, check:
- Is cell Q35 > C13?
- If no, remain the same
- If yes, step C21 down 1 integer
- Is cell Q35 STILL > C13 after stepping down 1 integer?
- If no, remain the same
- If yes, step C21 down 1 integer
- This logic check would then repeat down to a minimum value of "1"
- Is cell Q35 > C13?
- C21 starts at an initial value above
My code currently works but is ugly and inefficient:
>>> use code - tags <<<
Code:
If Q1.Range("C19") >= "4" Then
Q1.Range("C21").Value = "4"
End If
If Q1.Range("C13").Value = "0" Then
Q1.Range("C21").Value = "4"
End If
If Q1.Range("Q35").Value > Q1.Range("C13").Value Then
Q1.Range("C21").Value = "3"
End If
If Q1.Range("Q35").Value > Q1.Range("C13").Value Then
Q1.Range("C21").Value = "2"
End If
If Q1.Range("Q35").Value > Q1.Range("C13").Value Then
Q1.Range("C21").Value = "1"
End If
If Q1.Range("C19").Value = "3" Then
Q1.Range("C21").Value = "3"
End If
If Q1.Range("C13").Value = "0" Then
Q1.Range("C21").Value = "3"
End If
If Q1.Range("Q35").Value > Q1.Range("C13").Value Then
Q1.Range("C21").Value = "2"
End If
If Q1.Range("Q35").Value > Q1.Range("C13").Value Then
Q1.Range("C21").Value = "1"
End If
Last edited by a moderator: