But the order of placement into those cells is:
C3:C17 then E3:E17 then C18:C32 then E18:E32
If yes, then right click on the worksheet tab that should have this behavior.
Select view code and paste this in:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRng As Range
Dim myCell As Range
Dim myArray() As Variant
Dim iCtr As Long
Dim TotalElements As Long
If Target.Cells.Count > 1 Then Exit Sub
'change this line to match the cell where you'll do your data entry
If Intersect(Target, Range("a1")) Is Nothing Then Exit Sub
If Trim(Target.Value) = "" Then Exit Sub
Set myRng = Range("C3:C17,E3:E17,C18:C32,E18:E32")
If Application.CountA(myRng) = myRng.Cells.Count Then
MsgBox "No empty cells for new name!"
Beep
Exit Sub
End If
ReDim myArray(1 To myRng.Cells.Count)
myArray(1) = Target.Value
iCtr = 1
For Each myCell In myRng.Cells
If Trim(myCell.Value) <> "" Then
iCtr = iCtr + 1
myArray(iCtr) = myCell.Value
End If
Next myCell
TotalElements = iCtr
Call QuickSort(myArray(), 1, TotalElements)
iCtr = 0
Application.EnableEvents = False
For Each myCell In myRng.Cells
iCtr = iCtr + 1
If iCtr > TotalElements Then
myCell.Value = ""
Else
myCell.Value = myArray(iCtr)
End If
Next myCell
Target.Value = ""
Application.EnableEvents = True
End Sub
Then Insert|Module from the VBE toolbar to insert a general module. Paste this
in:
Option Explicit
Sub QuickSort(SortArray, L, R)
'from Jim Rech
'
http://google.com/[email protected]
'one line in your browser
Dim i, j, X, Y
i = L
j = R
X = SortArray((L + R) / 2)
While (i <= j)
While (SortArray(i) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j) And j > L)
j = j - 1
Wend
If (i <= j) Then
Y = SortArray(i)
SortArray(i) = SortArray(j)
SortArray(j) = Y
i = i + 1
j = j - 1
End If
Wend
If (L < j) Then Call QuickSort(SortArray, L, j)
If (i < R) Then Call QuickSort(SortArray, i, R)
End Sub