vbOKCancel code will not work

ejs7597

New Member
Joined
Sep 25, 2006
Messages
35
I have some simple code that is causing me to pull out my hair.
All it does is check to see if the value in cell "AK" & i (i being equeal to the active cell row, =1. This part is working, if the value is = to 1 then the msg box pops up, allowing me to choose, Yes or No. I have told it if
vbYes then put the text "yes" in a cell. The problem is that if, I click yes, it does nothing, and yes or no msg box will not go away. If I click no, then it puts "yes" in the cell I requested and the msg box goes away. I can click the Yes button forever, but it will not go away. It is like it is stuck in a loop or something. Any help would be appreciated. I have also tried putting different values into the cell, ex: other text or numbers.

Thanks

Private Sub Worksheet_Change(ByVal Target As Range)

i = ActiveCell.Row

If Range("AK" & i) = 1 Then

Dim myLabel

myLabel = MsgBox("Do you need a BARCODE LABEL", vbYesNo)

If myLabel = vbYes Then
Range("AL" & i) = "yes"

End If

End If


End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
When the code enter "yes" to the cell, another execution of Change event will heppen.
Therefore, your code will go endless circular execution of code...
try the code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim i As Long, myLabel As Integer
i = Target.Row

If Range("AK" & i) = 1 Then   
     myLabel = MsgBox("Do you need a BARCODE LABEL", vbYesNo)
       If myLabel = 6 Then
           Application.EnableEvents = False
           Range("AL" & i) = "yes"
           Application.EnableEvents = True
       End If
End If
 
 
End Sub
 
Joined
Jul 30, 2006
Messages
3,656
Try this code:

'----------Code Begins Here--------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("AK:AK")) Is Nothing Then
Cancel = False 'Do nothing
i = ActiveCell.Row
Dim myLabel
If Range("AK" & i) = 1 Then
myLabel = MsgBox("Do you need a BARCODE LABEL", vbYesNo)
If myLabel = vbYes Then
Range("AL" & i) = "yes"
End If
End If
End If

End Sub
'----------Code Ends Here----------------------------------


Have a great day,
Stan
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Try this code:

'----------Code Begins Here--------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("AK:AK")) Is Nothing Then
Cancel = False 'Do nothing
i = ActiveCell.Row
Dim myLabel
If Range("AK" & i) = 1 Then
myLabel = MsgBox("Do you need a BARCODE LABEL", vbYesNo)
If myLabel = vbYes Then
Range("AL" & i) = "yes"
End If
End If
End If

End Sub
'----------Code Ends Here----------------------------------


Have a great day,
Stan

What does the line of

Cancel = False ?

Cancel is defined nowhere...
 

Forum statistics

Threads
1,136,277
Messages
5,674,795
Members
419,525
Latest member
mountainkids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top