LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 154
Default Do not duplicate number

My apologies, I have coded this so that it has got to find an error in the
first line... amended:

Sub Ext_Check()
Dim xlssheet As Excel.Worksheet
Dim x As Long
Dim y As Long
Dim rng As String
Dim val As String
Dim loc As String
Dim msgstr As String

Set xlssheet = Excel.ActiveSheet

rng = InputBox("Enter Range of Cells (i.e. A1:A10)", "Range")

xlssheet.Range(rng).Select
y = Selection.Rows.Count
x = 1

For x = 1 To y + 1
Selection.Cells(x, 1).Activate
val = ActiveCell.Value
loc = ActiveCell.Address
Selection.Cells(x + 1, 1).Activate
If ActiveCell.Address < loc Then
If ActiveCell.Value = val Then
msgstr = "Extension currently in use. Please double check." & vbCrLf & "(" &
loc & "=" & ActiveCell.Address & ")"
msgbox msgstr, vbOKOnly, "Error"
Exit Sub
End If
End If
Next
End Sub

--
--Thomas [PBD]
Working hard to make working easy.


"Thomas [PBD]" wrote:

You can also use a Macro to do the validation check:

Sub Ext_Check()
Dim xlssheet As Excel.Worksheet
Dim x As Long
Dim y As Long
Dim rng As String
Dim val As String
Dim loc As String
Dim msgstr As String

Set xlssheet = Excel.ActiveSheet

rng = InputBox("Enter Range of Cells (i.e. A1:A10)", "Range")

xlssheet.Range(rng).Select
y = Selection.Cells.Count

Do Until ActiveCell.Value = ""
val = ActiveCell.Value
loc = ActiveCell.Address
Do Until ActiveCell.Value = ""
For x = 1 To y
Selection.Cells(x, 1).Activate
If ActiveCell.Address < loc Then
If ActiveCell.Value = val Then
msgstr = "Extension currently in use. Please double check." & vbCrLf & "(" &
loc & "=" & ActiveCell.Address & ")"
MsgBox msgstr, vbOKOnly, "Error"
Exit Sub
End If
End If
Next
Loop
Loop
End Sub

--
--Thomas [PBD]
Working hard to make working easy.


"Wanna Learn" wrote:

Hello I have a long spreadsheet that has a column with extension numbers. I
do not want the same extension to be entered twice , (not 2 people can have
the same extension number) Is it possible to have an error message pop up
when a duplicate extension number is entered in the spreadsheet? I have
excel 2002 thanks in advance

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Number of Duplicate Occurances Scott Halper Excel Worksheet Functions 7 March 30th 07 03:42 PM
How can I check for a duplicate number in a column in Excel? kkinner Excel Discussion (Misc queries) 2 August 24th 06 03:44 PM
How Excel can tell me i have entered a duplicate number Autofill Excel Discussion (Misc queries) 2 July 12th 06 12:08 PM
Return Row Number of LAST Numeric Consecutive Duplicate in Column Sam via OfficeKB.com Excel Worksheet Functions 10 July 7th 06 04:18 AM
duplicate number Daniell Excel Discussion (Misc queries) 1 March 16th 05 07:02 PM


All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"