Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Excel 04: match column entries

Original Message
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?

Thanks!

Johannes


Report Offensive Message For Removal


Response Number 1
Name: DerbyDad03
Date: May 7, 2008 at 18:37:20 Pacific
Subject: Excel 04: match column entries
Reply: (edit)
It can be done fairly easily with VBA.

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


Report Offensive Follow Up For Removal

Response Number 2
Name: juanito671
Date: May 8, 2008 at 09:20:26 Pacific
Subject: Excel 04: match column entries
Reply: (edit)
Thanks for the fast response!

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


It tells me I have a syntax error

Johannes


Report Offensive Follow Up For Removal

Response Number 3
Name: DerbyDad03
Date: May 8, 2008 at 10:19:53 Pacific
Subject: Excel 04: match column entries
Reply: (edit)
Which piece of code is giving you the syntax error, mine or yours?

If it's mine, look for the line that reads:

shift:=xlDown

When I pasted the code from your post into the VBA editor, it put shift:=xlDown on it's own line, when it should be part of the line above.

The following should all be one line, with a space between Insert and shift:=xlDown

Range("B" & NxtName & ":C" & NxtName).Insert shift:=xlDown

If it's your code, try deleting the () after Match_Entries.

Private Sub CommandButton1_Click()
UserForm1.Match_Entries
End Sub


Report Offensive Follow Up For Removal

Response Number 4
Name: juanito671
Date: May 8, 2008 at 12:21:32 Pacific
Subject: Excel 04: match column entries
Reply: (edit)
Ah, that must have been the problem.

Thanks so much, you just saved me about a week of work!

Johannes


Report Offensive Follow Up For Removal

Response Number 5
Name: DerbyDad03
Date: May 8, 2008 at 12:51:24 Pacific
Subject: Excel 04: match column entries
Reply: (edit)
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.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Excel 04: match column entries

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




CPU and Graphics Upgrade Questions

VIRUS ALERT in Taskbar, HELP!

DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12


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

All content ©1996-2007 Computing.Net, LLC