Name: juanito671 Date: May 7, 2008 at 15:30:24 Pacific Subject: Excel 04: match column entries OS: OS X 10.4.11 CPU/Ram: 1.5 GHz PowerPC G4
Comment:
I have two columns, one of which is a subset of the other, both sorted in the same way, and a third column that is tied to the second one.
Example: A B C Arabia Arabia 12.5 Africa Albania 31.2 Albania Mexico 52 Macedonia Mexico Norway . . .
I would like to arrange the columns so that entries in column B match up with entries in column A while keeping the numbers in C next to the corresponding entries in B.
Thus, I want it to look like this:
A B C Arabia Arabia 12.5 Africa Albania Albania 31.2 Macedonia Mexico Mexico 52 Norway . . .
Does anyone know how to do this with a few excel commands?
This code assumes your data begins in Row 2 - in other words, it assumes you have column headers in Row 1.
Sub Match_Entries() 'Determine how long the List in Column A is LastRow = Range("A" & Rows.Count).End(xlUp).Row 'Loop through the short list 'Compare the value in B to the value in A 'If they don't match, insert cells in Columns B & C 'When they match, stop checking For NxtName = 2 To LastRow If Range("B" & NxtName) <> "" And _ Range("B" & NxtName) <> Range("A" & NxtName) Then Range("B" & NxtName & ":C" & NxtName).Insert shift:=xlDown Else: End If Next End Sub
I inserted your code, just can't get the command button to work.
Here is what I have so far:
Sub Match_Entries() 'Determine how long the List in Column A is LastRow = Range("A" & Rows.Count).End(xlUp).Row 'Loop through the short list 'Compare the value in B to the value in A 'If they don't match, insert cells in Columns B & C 'When they match, stop checking For NxtName = 1 To LastRow If Range("B" & NxtName) <> "" And _ Range("B" & NxtName) <> Range("A" & NxtName) Then Range("B" & NxtName & ":C" & NxtName).Insert shift:=xlDown Else: End If Next End Sub
Private Sub CommandButton1_Click() UserForm1.Match_Entries() End Sub
Glad I could help and thanks for the acknowledgement.
So often in this forum we never know if our suggestions help or not 'cuz we never hear back from the OP.
The other day someone asked a question and said it was "Urgent!" I asked for a little more detail and never got an answer. Makes me wonder how "Urgent!" it really was.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE