Add Msgbox

Prasad K

Board Regular
Joined
Aug 4, 2021
Messages
189
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
Hi i have data with Bike Sales in my sheet

i want to add this line "Do you want to change Mobile No Click "Yes" in this below vba
add Yes or No Options in this code if i click "Yes" then it will go to that mobile no cell

i have data like this
Column A - Customer Name
Column B - Mobile Number
Column C - Address
Column D - Purchased Bike
Column E - Purchased Date


VBA Code:
Sub SearchNreturn()
Dim Rng As Range
Dim mblNo As String

mblNo = InputBox("Enter Mobile No")
Set Rng = Sheets("Sales").Range("B:B").Find(What:=mblNo, _
            After:=Cells(1, 2), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False)

            If Not Rng Is Nothing Then
               MsgBox "Customer Name: - " & Rng.Offset(0, -1) & vbNewLine & _
                    vbNewLine & _
                      "Mobile: - " & Rng.Value & vbNewLine & _
                    vbNewLine & _
                      "Purchased Bike: " & Rng.Offset(0, 2) & vbNewLine & _
                    vbNewLine & _
                      "Purchased Date: " & Rng.Offset(0, 3) & vbNewLine & _
                    vbNewLine & _
                      "Address: - " & Rng.Offset(0, 1)
                   
                Else
                MsgBox "No Details Found in Data."
            End If
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about
VBA Code:
Sub SearchNreturn()
Dim Rng As Range
Dim mblNo As String

mblNo = InputBox("Enter Mobile No")
Set Rng = Sheets("Sales").Range("B:B").Find(What:=mblNo, _
            After:=Cells(1, 2), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False)

            If Not Rng Is Nothing Then
               MsgBox "Customer Name: - " & Rng.Offset(0, -1) & vbNewLine & _
                    vbNewLine & _
                      "Mobile: - " & Rng.Value & vbNewLine & _
                    vbNewLine & _
                      "Purchased Bike: " & Rng.Offset(0, 2) & vbNewLine & _
                    vbNewLine & _
                      "Purchased Date: " & Rng.Offset(0, 3) & vbNewLine & _
                    vbNewLine & _
                      "Address: - " & Rng.Offset(0, 1)
                If MsgBox("Do you want to change Mobile No Click", vbYesNo) = vbYes Then
                    Application.Goto Rng, True
                End If
            Else
                MsgBox "No Details Found in Data."
            End If
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub SearchNreturn()
Dim Rng As Range
Dim mblNo As String

mblNo = InputBox("Enter Mobile No")
Set Rng = Sheets("Sales").Range("B:B").Find(What:=mblNo, _
            After:=Cells(1, 2), _
            LookIn:=xlValues, _
            LookAt:=xlPart, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False)

            If Not Rng Is Nothing Then
               MsgBox "Customer Name: - " & Rng.Offset(0, -1) & vbNewLine & _
                    vbNewLine & _
                      "Mobile: - " & Rng.Value & vbNewLine & _
                    vbNewLine & _
                      "Purchased Bike: " & Rng.Offset(0, 2) & vbNewLine & _
                    vbNewLine & _
                      "Purchased Date: " & Rng.Offset(0, 3) & vbNewLine & _
                    vbNewLine & _
                      "Address: - " & Rng.Offset(0, 1)
                If MsgBox("Do you want to change Mobile No Click", vbYesNo) = vbYes Then
                    Application.Goto Rng, True
                End If
            Else
                MsgBox "No Details Found in Data."
            End If
End Sub
Thank you so much Fluff
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,082
Members
449,205
Latest member
Healthydogs

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
Back
Top