Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Return Col for best alphabetical fit

Since the columns are sorted, how about a strategy like this:

1. compare the entered name with the last name in col A
2. if the result of step 1 is less then you found your col, put the name in
col A and sort that col
3. else compare the entered name with the last name in col D
4. and so on

"David Turner" wrote in message
...
Using XL2K, I have a sheet that has names (lastname, firstname) already
alphabetized in Cols A, D & G and a VBA routine that now asks the user
what column they want to add a name to, has the user supply a new name,
then adds that name to that column and sorts that range. I would like to
eliminate the first step and have the code add the name to the range with
the best alphabetical fit.

I would need some code to return that column letter since my routine also
has some conditions based on that column letter:

Sub Add_Member()
Dim New_Member As String, Col As String, rng As Range
Col = UCase(InputBox("Which Column, A or D or G?" & vbLf & vbLf _
& "Hint: Choose column where name" & vbLf & _
" will fit best alphabetically", , "A"))
If Col = "" Then Exit Sub
If Not (Col = "A" Or Col = "D" Or Col = "G") Then
MsgBox "Invalid entry": Exit Sub
End If
If Range(Cells(6, Col), Cells(6, Col)) = "" Then
MsgBox "Enter name manually": Exit Sub
End If
Set rng = Range(Cells(5, Col), Cells(5, Col).End(xlDown).Offset(1, 0))
If Col = "A" Then Maxed = rng(rng.Rows.Count).Offset(1, 3).Value
If Col = "D" Then Maxed = rng(rng.Rows.Count).Offset(1, 0).Value
If Col = "G" Then Maxed = rng(rng.Rows.Count).Offset(1, -3).Value
If Maxed = "Number in Educational Track" Then
MsgBox "This Column Full!!": Exit Sub
End If
New_Member = UCase(InputBox("Type New Member's Name" & _
vbNewLine & vbNewLine & "Like This: LastName, FirstName"))
If New_Member = "" Then Exit Sub
Application.ScreenUpdating = False
rng(rng.Rows.Count) = New_Member
rng.Resize(, 3).Sort Key1:=rng, Order1:=xlAscending
Application.ScreenUpdating = True
End Sub

--
David



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Return Col for best alphabetical fit

kiat wrote

Since the columns are sorted, how about a strategy like this:

1. compare the entered name with the last name in col A
2. if the result of step 1 is less then you found your col, put the
name in col A and sort that col
3. else compare the entered name with the last name in col D
4. and so on


Sounds like a good strategy, only I don't know how to compare them with
code, particularly if the new last name begins with a letter that may not
be in any of the 3 existing lists.

--
David
Reply
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
Alphabetical Selection Not Excelerated[_2_] Setting up and Configuration of Excel 1 May 14th 08 09:45 PM
alphabetical sort Jock Excel Worksheet Functions 4 November 2nd 07 09:59 AM
Sort - Not Alphabetical tommcbrny Excel Discussion (Misc queries) 1 April 16th 07 09:25 PM
Alphabetical Lists CW Excel Discussion (Misc queries) 6 July 11th 06 04:32 PM
alphabetical list Ronnie New Users to Excel 7 July 28th 05 10:41 PM


All times are GMT +1. The time now is 07:15 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"