Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing cells in Excel

Status
Not open for further replies.

djeverett01

Programmer
Aug 24, 2001
16
US
I have a spreadsheet where I enter a random number(column A) and a name(Column B).Once I have all of my names entered I then have some code that radomly sorts the names and places them into numerical order. This is for a competition so we know who will go in what order. Once I have the run order sorted I want to be able to check and make sure that no one is back to back, meaning that the same person does not have to run two times in a row. I want to seperate them by at least 5 spots if they are back to back. Is this possible? Does anyone know how to accomplish this?[puppy]
 
Hi,

Well it seems to me that you would begin at the top of your list and run thru it in a For...Next loop.

For each name in the list, you'd have an embedded loop that would test the next name in the list.

If you encounter a match, then you have to decide what to do with one of the rows in that pair.

:)

Skip,
Skip@TheOfficeExperts.com
 
Come on. Help me out!

"The cell" STARTS in B2??? A cell can only be a cell.

The data to compare starts in B2, is 1 column wide and is contiguous to the bottom -- would that be a fair description of ONE of the data elements?

What about the other? Have to compare this with SOMETHING. Where is that data? What are we comparing? What do you want to see if there's a match or NOT?

PLEASE GET SPECIFIC!


Skip,
Skip@TheOfficeExperts.com
 
I have a spreadsheet with two columns(A & B). Column A contains a random number that is entered if there is data in Column B. Column B contains the name of a person. I can give you an example of what I don't want to happen...

Column A Column B
1 John Doe
2 John Doe
3 Jane Doe
4 John Smith
5 Bugs Bunny
6 Mickey Mouse

I do not want John Doe to have to go back to back as in the example above. If this happens I would for the spreadsheet to redraw the order(which I already have working with the push of a button, but I would like for it to do it automatically) so that John Doe is not back to back. I would like to put a few spaces between the two turns. So then it would look like this...

Column A Column B
1 John Doe
2 Mickey Mouse
3 Jane Doe
4 John Smith
5 Bugs Bunny
6 John Doe

So I am comparing the cell B2 with cell B3 and so on. Does this help any or is this impossible to do?

Dawn Nelson Everett
 
Code:
Sub MoveAdjacentNames()
    For Each c In Range(Cells(1, 2), Cells(1, 2).End(xlDown))
      With c
        If .Value = .Offset(1, 0).Value Then
           .Offset(1, 0).EntireRow.Cut
           .Offset(5, -1).Insert (xlDown)
        End If
      End With
    Next
End Sub
Hows that do?

Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top