Return Col for best alphabetical fit
Try this:
Sub Add_Member()
Dim xRow As Long, i As Long
Dim strNewNm As String
Do
strNewNm = UCase(InputBox("Type New Member's Name" & _
vbNewLine & vbNewLine & "Like This: LastName, FirstName"))
If Len(strNewNm) Then
For i = 1 To 7 Step 3
xRow = Cells(5, i).End(xlDown).Row
If StrComp(Cells(xRow, i).Text, strNewNm, vbTextCompare) = 1 Or
i = 7 Then
xRow = xRow + 1
Cells(xRow, i) = strNewNm
Range(Cells(5, i), Cells(xRow, i + 3)).Sort Cells(5, i)
Exit For
End If
Next
Else
Exit Do
End If
Loop
End Sub
Warning, this code has serious limitation, it fovaors to put names in column
G. I think you should consider Dave Peterson's strategy and change the code
there to suit your needs.
"David Turner" wrote in message
...
kiat wrote
not the kinda coding my professor would approve, but if it works,
well...
I'm open to new ideas, if you care to share. Your For...Next...Case idea
was very valuable in eliminating the need to specify the target column
ahead of time. I must admit, I don't understand the Case stuff and am
flying blind when implementing it.
BTW, I discovered later I had to put the sort line BEFORE Next i
I've also found in my morphed Add_Member routine that I can't add a name
that would fall alphabetically AFTER the last name in Col G. :(
--
David
|