PDA

View Full Version : stop incrementing



johan4b
09-14-2016, 06:43 AM
Can somebody help me with this code.

I want that vba stops incrementing when the value in b4 is Yes.

Can someone tell what i did wrong

thank you

Private Sub CommandButton4_Click()


For intCount = 15 To 150
Range("B2") = intCount
If (intCount = Range("B4")) = "YES" Then
Range("B2") = "YES"
intCount = 150

End If

Next intCount
End Sub

Paul_Hossler
09-14-2016, 07:18 AM
I'm not sure about your intent, like how does B4 get set to YES





Private Sub CommandButton4_Click()

For intCount = 15 To 150
Range("B2") = intCount

If Range("B4") = "YES" Then
Range("B2") = "YES"
Exit For
End If
Next intCount

End Sub

mana
09-14-2016, 07:20 AM
if range("b4").value="yes" then exit for

SamT
09-14-2016, 07:42 AM
About: If (intCount = Range("B4")) = "YES"

intCount = Range("B4") Returns True or False, Not String "YES"

True <> "YES"
False <> "YES"


About: For intCount = 15 To 150

For intCount = 15 To 150
'
intCount = 150
'
Next intCount = 151, NO! Will be no next loop.

SamT
09-14-2016, 07:47 AM
Double posting: http://www.vbaexpress.com/forum/showthread.php?57147-Automatically-increment-single-cell-from-15-to-150