Hi,
I have a following code in my workbook
i want to add vbyesno code with
If rngFound Is Nothing Then
MsgBox "ID not Found, Want to Create?" vbyesno
PHP Code:
Private Sub cmdfndnext_Click() Dim strPrefix As String, strSuffix As String, strID As String Dim rngFound As Range, rngstart As Range Dim i As Long
strID = Trim(txtid.Text)
If cmdfndnext.Tag = "Next" Then Rem incriment ID number For i = Len(strID) To 1 Step -1 If Mid(strID, i, 1) Like "[!0-9]" Then strPrefix = Left(strID, i) strSuffix = Mid(strID, i + 1) If i < Len(strID) Then strSuffix = Format(Val(strSuffix) + 1, String(Len(strSuffix), "0")) End If Exit For End If Next i strID = strPrefix & strSuffix txtid.Text = strID
End If
With Sheets("Life Member").Range("A:A") On Error Resume Next Set rngFound = .Find(txtid.Text, After:=.Cells(Rows.Count, 1), Lookat:=xlWhole, LookIn:=xlValues, MatchCase:=True) On Error GoTo 0 End With
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.
Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.
Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
(This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
Private Sub cmdfndnext_Click() Dim strPrefix As String, strSuffix As String, strID As String Dim rngFound As Range, rngstart As Range Dim i As Long
strID = Trim(txtid.Text)
If cmdfndnext.Tag = "Next" Then Rem incriment ID number For i = Len(strID) To 1 Step -1 If Mid(strID, i, 1) Like "[!0-9]" Then strPrefix = Left(strID, i) strSuffix = Mid(strID, i + 1) If i < Len(strID) Then strSuffix = Format(Val(strSuffix) + 1, String(Len(strSuffix), "0")) End If Exit For End If Next i strID = strPrefix & strSuffix txtid.Text = strID
End If
With Sheets("Life Member").Range("A:A") On Error Resume Next Set rngFound = .Find(txtid.Text, After:=.Cells(Rows.Count, 1), Lookat:=xlWhole, LookIn:=xlValues, MatchCase:=True) On Error GoTo 0 End With
In the future, please keep in mind that the correct way to address this is not to submit a new post but to edit the post that needs code tags.
Also I suggest you use CODE tags instead of PHP tags.
Your code does not use the example I posted. Is there something that is not clear about the example? The point is that you assign the result of the MsgBox function to a variable, then test that variable using your If statement to determine how the user answered.
Office 365, Excel for Windows 2010 & Excel for Mac
Posts
29,464
Re: Add vbyes no code
Unless I'm misunderstanding this you already have the an IF Then Else End If code bloc which the macro can process without any further input, so I'm not sure why you want a Message Box. What does this bring to the party?
Richard Buttrey
RIP - d. 06/10/2022
If any of the responses have helped then please consider rating them by clicking the small star icon below the post.
Bookmarks