Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
rk0909
 
Posts: n/a
Default getting out of a if loop

hi All,
I have a VBA code for a change event associated with a particular cell, say
A1. If the value in A1 is less than 500 a message box is displayed that you
have to enter something freater than 500. If it is less than 500 I want the
value of A1=0. But now since 0 is less than 500 code goes into an infinite
loop of showing the msgbox. How do I get out of this loop.
Any help or guidance is appreciated.
Thanks,
RK
  #2   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey
 
Posts: n/a
Default getting out of a if loop

One way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If .Address(False, False) = "A1" Then
If IsNumeric(.Value) Then
If .Value < 500 Then
MsgBox "Must be 500 or greater"
Application.EnableEvents = False
.Value = 0
Application.EnableEvents = True
End If
End If
End If
End With
End Sub


In article ,
rk0909 wrote:

hi All,
I have a VBA code for a change event associated with a particular cell, say
A1. If the value in A1 is less than 500 a message box is displayed that you
have to enter something freater than 500. If it is less than 500 I want the
value of A1=0. But now since 0 is less than 500 code goes into an infinite
loop of showing the msgbox. How do I get out of this loop.
Any help or guidance is appreciated.
Thanks,
RK

  #3   Report Post  
Posted to microsoft.public.excel.misc
RogerN
 
Posts: n/a
Default getting out of a if loop

I would use Data/Validation, set the minimum value at 500 and use the
facilities within this to provide the necessary message.

If you set the original value to 0, before setting the validation, the user
can leave the value at 0 by using Cancel.

Roger

"rk0909" wrote:

hi All,
I have a VBA code for a change event associated with a particular cell, say
A1. If the value in A1 is less than 500 a message box is displayed that you
have to enter something freater than 500. If it is less than 500 I want the
value of A1=0. But now since 0 is less than 500 code goes into an infinite
loop of showing the msgbox. How do I get out of this loop.
Any help or guidance is appreciated.
Thanks,
RK

  #4   Report Post  
Posted to microsoft.public.excel.misc
rk0909
 
Posts: n/a
Default getting out of a if loop

thanks a lot works perfect.
RK

"JE McGimpsey" wrote:

One way:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If .Address(False, False) = "A1" Then
If IsNumeric(.Value) Then
If .Value < 500 Then
MsgBox "Must be 500 or greater"
Application.EnableEvents = False
.Value = 0
Application.EnableEvents = True
End If
End If
End If
End With
End Sub


In article ,
rk0909 wrote:

hi All,
I have a VBA code for a change event associated with a particular cell, say
A1. If the value in A1 is less than 500 a message box is displayed that you
have to enter something freater than 500. If it is less than 500 I want the
value of A1=0. But now since 0 is less than 500 code goes into an infinite
loop of showing the msgbox. How do I get out of this loop.
Any help or guidance is appreciated.
Thanks,
RK


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop time seems dependent on unrelated workbook - Why? Richard Excel Worksheet Functions 2 March 30th 06 11:59 PM
Loop gone crazy Dave Peterson Excel Discussion (Misc queries) 4 December 16th 05 03:38 PM
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM
hysteresis loop olivekim Charts and Charting in Excel 1 October 28th 05 04:22 AM
loop trough e-mail address list to send task lists with outlook Paul. Excel Discussion (Misc queries) 2 April 14th 05 11:48 AM


All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"