Coding

E

eenglish

What would be the correct code for the following macro:

Sub Calc()
If [B13] < [D3] + 1 Then [D13] = [D5] + 1
End If
If [B13] > [D3] Then [D13] = [D5]
End If
If [B13] = 0 Then [D13] = [D5]
End If
End Sub

All cells are numeric values 0 up
 
R

Ron Rosenfeld

What would be the correct code for the following macro:

Sub Calc()
If [B13] < [D3] + 1 Then [D13] = [D5] + 1
End If
If [B13] > [D3] Then [D13] = [D5]
End If
If [B13] = 0 Then [D13] = [D5]
End If
End Sub

All cells are numeric values 0 up

Perhaps:

Select Case [b13]
Case Is < [d3] + 1
[d13] = [d5] + 1
Case Is = 0 Or [d5]
[d13] = [d5]
End Select
 
R

Rick Rothstein

What would be the correct code for the following macro:
Sub Calc()
If [B13] < [D3] + 1 Then [D13] = [D5] + 1
End If
If [B13] > [D3] Then [D13] = [D5]
End If
If [B13] = 0 Then [D13] = [D5]
End If
End Sub

All cells are numeric values 0 up

What about if [B13] = [D3]? Or was that what you meant to type for your last
If..Then statement? Assuming that is what you meant, try this...

[D13] = [D5] - ([B13] < [D3] + 1)

Rick Rothstein (MVP - Excel)
 
R

Rick Rothstein

What would be the correct code for the following macro:
Sub Calc()
If [B13] < [D3] + 1 Then [D13] = [D5] + 1
End If
If [B13] > [D3] Then [D13] = [D5]
End If
If [B13] = 0 Then [D13] = [D5]
End If
End Sub

All cells are numeric values 0 up

What about if [B13] = [D3]? Or was that what you meant to type for your
last If..Then statement? Assuming that is what you meant, try this...

[D13] = [D5] - ([B13] < [D3] + 1)

Actually, in looking at what you wrote more carefully, I think you might
actually want this (I'm assuming your numbers are always whole numbers)...

[D13] = [D5] - (([B13] < [D3] + 1) And ([B13] <> 0))

Rick Rothstein (MVP - Excel)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top