ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,726
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the code supplied below.
When i open my worksheet i start to type a customers name in cell A6
When i leave the cell the code checks to see if this customer has purchased from me before by looking down column A & if so it then shows me the msgbox "A Duplicated Customers Name Was Found" etc etc
Customers name sequence are entered / saved like so,
TOM JONES
TOM JONES 001
TOM JONES 002
TOM JONES 003
So next time i i enter TOM JONES as opposed to me seeing the msgbox can we just have the code check column A then apply the next number in the sequence.
So i type in cell A6 TOM JONES, when i then leave the cell & the code checks column A for this name & if a match is found it would then apply in this case 004 so cell A6 then shows TOM JONES 004, if no match is found then leave the name typed in A6 as it is, this would be much easier for me.
Many thanks & have a nice day.
I am using the code supplied below.
When i open my worksheet i start to type a customers name in cell A6
When i leave the cell the code checks to see if this customer has purchased from me before by looking down column A & if so it then shows me the msgbox "A Duplicated Customers Name Was Found" etc etc
Customers name sequence are entered / saved like so,
TOM JONES
TOM JONES 001
TOM JONES 002
TOM JONES 003
So next time i i enter TOM JONES as opposed to me seeing the msgbox can we just have the code check column A then apply the next number in the sequence.
So i type in cell A6 TOM JONES, when i then leave the cell & the code checks column A for this name & if a match is found it would then apply in this case 004 so cell A6 then shows TOM JONES 004, if no match is found then leave the name typed in A6 as it is, this would be much easier for me.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A6").Address Then
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim SearchString As String
Dim SearchRange As Range
Dim r As Long
Dim ans As Variant
SearchString = Target.Value
Set SearchRange = Range("A7:A" & lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If Not SearchRange Is Nothing Then
r = SearchRange.Row
ans = MsgBox("A Duplicated Customers Name Was Found." & vbNewLine & " " & vbNewLine & "Click Yes To View Their Details", vbYesNo + vbCritical, "DUPLICATED CUSTOMER NAME MESSAGE")
If ans = vbYes Then Application.Goto Range("A" & r)
End If
End If
Dim rng As Range, c As Range
Set rng = Intersect(Target, Rows(6))
If Not rng Is Nothing Then
If rng.Cells.Count < Me.Columns.Count Then
Application.EnableEvents = False
For Each c In rng
c.Value = UCase(c.Value)
Next
Application.EnableEvents = True
End If
End If
End Sub
Many thanks & have a nice day.