Yes button in vbyesno not working...

ellehcer08

New Member
Joined
Jul 25, 2011
Messages
31
hi!! can someone tell me how to make this code work.. (button YES, in vbYesNo is not working)

Code:
Private Sub cmdDelete_Click()
  
Dim RecipeDel
Dim r As Range
Dim SourceDel As String
Dim CategoryDel As String
Dim faddress As String
Dim PageDel As String
    With Me
        CategoryDel = .lbxSearch.Column(1)
        RecipeDel = .lbxSearch.Column(2)
        SourceDel = .lbxSearch.Column(3)
        PageDel = .lbxSearch.Column(4)
    End With
    
    With Sheets("Recipe_Page").Range("RecipeRange")
    Set r = .Find(What:=CategoryDel, LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False)
    If Not r Is Nothing Then
        faddress = r.Address
        
        answer = MsgBox("Delete this??", vbYesNo)
        
        If vbNo Then Exit Sub
        End If
        
        If vbYes Then
        Do
            If r.Offset(0, 1) = RecipeDel And r.Offset(0, 2) = SourceDel And _
                r.Offset(0, 3) = PageDel Then
                r.EntireRow.Delete
        Exit Do
        End If
                
  
        Set r = .FindNext(r)
    Loop While Not r Is Nothing And r.Address <> faddress

Else
    MsgBox "Nothing found... Try Again!!", vbInformation + vbOKOnly
    Me.txtSearch = ""
    Me.txtSearch.SetFocus
End If

 
End With
    With Me
        .txtSearch.Value = ""
        .txtRecipe.Value = ""
        .txtPageNum.Value = ""
        .cboCategory2.Value = ""
        .cboSource2.Value = ""
        .lbxSearch.Clear
        .cmdAdd.Enabled = True
        .cmdGO.Enabled = True
        .cmdDelete.Enabled = False
        .cmdReplace.Enabled = False
    End With
End Sub


Please help!!!! thanks a lot...
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try

If answer = vbNo Then ...
If answer = vbYes Then ...
 

Forum statistics

Threads
1,081,619
Messages
5,360,064
Members
400,566
Latest member
Usr3

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top