I need help in this macro

Status
Not open for further replies.

Prasad K

Board Regular
Joined
Aug 4, 2021
Messages
130
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
In this below macro i want to show in second msgbox you have entered the mobile number is already exists in cell B4

If I type same mobile number in column B cell range then it will show me above message


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim answer As Integer

If Not Intersect(Target, Range("B:B")) Is Nothing Then
On Error Resume Next
If Len(Target.Cells) > 10 Or Len(Target.Cells) < 10 Then MsgBox _
    "Please check the number you have Enter The Mobile should be contain 10 Digits only"

If Application.CountIf(Columns(2), Target.Cells.Value) > 1 Then
    answer = MsgBox("You have Entered the Mobile Number is Already Exist in cell" _
        & vbNewLine & "If you want to continue with Duplicate Mobile Number click (YES)" _
            & vbNewLine & "If want to remove Duplicate Mobile Number in EnireRow click (NO)", _
                vbQuestion + vbYesNo + vbDefaultButton2, "Duplicate Entry")

If answer = vbNo Then
Target.Cells.EntireRow.Delete

End If
    End If
        End If
    
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Status
Not open for further replies.

Forum statistics

Threads
1,147,475
Messages
5,741,347
Members
423,656
Latest member
Medrok2021

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