Moonbeam111
Board Regular
- Joined
- Sep 24, 2018
- Messages
- 64
- Office Version
- 365
- 2010
I'm kind of new to vba and I'm having trouble with this loop. I want to continously subtract 0.0625 from range("I27") everytime the condition is met but with an extra 0.0625 each time the condition is met again. But there is something wrong with the code. It never gives x any value other than 0 and I'm not sure why. I thought of using multiple if statements but I don't think that's necessary and it would make the code redundant. Can anyone help me here?
VBA Code:
Dim x As Integer
If Range("H26") = "" Then
x = 0
End If
x = x + 0.0625
Range("m1") = x 'merely here to keep an eye on x's value
For x = 1 To 1 'not really sure what to put here
If Sheets("Sheet1").Range("H26") = "example text" And Sheets("Sheet1").Range("G41") = "example text" Then 'specific text criteria to match
Sheets("Sheet1").Range("I27") = WorksheetFunction.Max(0, Sheets("Sheet1").Range("I27") - x)
Sheets("Sheet1").Range("H28") = "example" & x & "% text"
Sheets("Sheet1").Range("H27") = Sheets("Sheet1").Range("H27") + 1 'count the number of times condition has been met
Exit For
End If
Next x