Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50061

Make 1 column All Caps, Alert when duplicate entry in another column, point out duplicate

$
0
0
Basically, I need to have whatever is entered into column E converted to All Caps upon exit of each Column E cell. I need to have the user alerted if they've entered a duplicate into Column G, then I need Excel to delete the duplicate the user just entered and take them back to the original entry so they can make updates within that data record if needed. I'm already using Data Validation to limit each cell in Column G to 10 digits. I don't want to use Data Validation to catch the duplicates, I want to use VBA code. I need for the code to catch duplicates whether they are manually entered or pasted in and show me where the original entry/entries are.

I have two Worksheet_Change subroutines that I need to work independently of each other, but I don't know how to combine them so they both work. One of my subroutines did work, but doesn't anymore. Hopefully someone can help me to modify the code so that I can get my spreadsheet to perform like I need it to.

For Worksheet_Change1 I need it to change whatever is entered into column E to all caps upon exiting the cell.

For Worksheet_Change I need it to look at the claim number entered in column G to make sure it is not a duplicate entry. If it is a duplicate I would like for a message box to pop up telling the user that the claim number has previously been entered and they either need to reenter a unique value or go to the previously entered claim number so they can modify the assignment date and adjuster name. I also want the message box to tell them when they click on the OK button they will be taken to the previous record so they can make the necessary adjustments. When they click OK to close the message box, I would like for the cell they just entered the duplicate information into to be cleared, then I would like for Excel to take them to the previously entered claim number in column G so they can proceed to make the appropriate changes. I would like this to work whether the duplicate number is manually entered or pasted into column G. Also, what is the best way to handle this if there are multiple duplicate entries in column G?


Here are the two subroutines that I need modified/combined and I need them to work independently of one another:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, r As Range, msg As String, msg1 As String, x As Range
Set rng = Intersect(Columns(7), Target)

If Not rng Is Nothing Then
Application.EnableEvents = False
For Each r In rng
If Not IsEmpty(r.Value) Then
If Application.CountIf(Columns(7), r.Value) > 1 Then
msg = msg & r.Value
msg1 = msg1 & r.Address(0, 0)

If x Is Nothing Then
r.Activate
Set x = r
Else
Set x = Union(x, r)
End If
End If
End If

Next

If Len(msg) Then
MsgBox "Claim number " & msg & " located in cell " & msg1 & " has previously been entered. " & _
"Please either enter a unique claim number in cell " & msg1 & " or change the assignment date " & _
"and adjuster name in the previously entered record.", vbOKOnly, "Duplicate Claim Number Entered"
x.ClearContents
x.Select
End If

Set rng = Nothing
Set x = Nothing
Application.EnableEvents = True

End If
End Sub






Private Sub Worksheet_Change1(ByVal Target As Excel.Range)
If Not Target.Column = 5 Then Exit Sub
On Error Goto ErrHandler
Application.EnableEvents = False
Target.Formula = UCase(Target.Formula)
ErrHandler:
Application.EnableEvents = True
End Sub
Attached Files

Viewing all articles
Browse latest Browse all 50061

Trending Articles