I need help in this macro

Status
Not open for further replies.

Prasad K

Board Regular
Joined
Aug 4, 2021
Messages
189
Office Version
  1. 2016
  2. 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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Status
Not open for further replies.

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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