|Here is some VBA code that should get the job done. |
I've offered 3 different ways to assign an Incremental value to Y: a hardcoded value, a reference to a cell and an InputBox to get the value from the user.
I've offered 2 different output methods: Place the count in a cell or present a Message Box to the user.
Remove/replace the comment symbols ' where appropriate to test the various options.
After the code, I've offered a brute force way to get the answer in an Excel spreadsheet.
BTW, if you are going to playing around with VBA, you should probably review this tutorial:
Dim X, Y, IncX, IncY
Y = Range("A1")
X = Range("B1")
IncX = 1
'Hardcode incremental value for Y
IncY = 3
'Use cell for incremental value for Y
'IncY = Range("C1")
''Get incremental value for Y from user, Exit if Cancelled
'IncY = Application.InputBox("Enter Increment Value For Y", _
"Incremental Value", Type:=1)
'If IncY = False Then Exit Sub
'Loop while incrementing Y and X, count loops
Do While Y < X
X = X + IncX
Y = Y + IncY
cntDays = cntDays + 1
'Set cntDays = 0 if Y is initially >= X
'This avoids a blank output
If cntDays = "" Then cntDays = 0
'Put Day Count in D1
Range("D1") = cntDays
'Present Day Count to user
'MsgBox "It took " & cntDays & _
" Days For Y to be equal to or greater than X", _
Title:="Day Count Result"
Enter your Y, X and IncY values in A1, B1 and C1 respectively. In each of the following formulas, make sure you use the $ exactly as shown.
In A2, enter this formula:
In B2, enter this formula:
In C2, enter this formula:
Drag all 3 formulas down until a value appears in Column C.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.