#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Vlookup

Hi,

I have a worksheet with 31,000 rows of data. I would like to use a vlookup
to return all the values listed in column b with its corresponding value is
column A

Colum A Column
B
000000xxc093NEF 0 20050225 Modality
000000xxc093NEF 0 20050225 CMT
000001239619UAL 0 20050126 Visit
000001239619UAL 0 20050126 E & M

I would like it to return:
Column A Column B
000000xxc093NEF 0 20050225 Modality, CMT
000001239619UAL 0 20050126 Visitss, E & M

I have search many threads, but just can't seem to find the one that fits my
need.

Thank you so much!!

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200607/1
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Vlookup

That's not really what =vlookup() does.

But you could use a macro to do it.

Make sure row 1 has headers in it and I'm assuming that there isn't anything
else in the worksheet besides the stuff in columns A and B.

Option Explicit
Sub testme()

Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim oRow As Long

Set CurWks = Worksheets("sheet1")
Set NewWks = Worksheets.Add
NewWks.Range("a1").Resize(1, 2).Value _
= CurWks.Range("a1").Resize(1, 2).Value

With CurWks
.Range("a:b").Sort key1:=.Range("a1"), order1:=xlAscending, _
key2:=.Range("b1"), order2:=xlAscending, _
header:=xlYes

FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

oRow = 1
For iRow = FirstRow To LastRow
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
If .Cells(iRow, "B").Value = .Cells(iRow - 1, "B").Value Then
'both col A and B are the same, do nothing!
'those values are already taken care of
Else
'Col A is the same, but col B is different
'so just add a comma and that value to the output
NewWks.Cells(oRow, "B").Value _
= NewWks.Cells(oRow, "B").Value & ", " _
& .Cells(iRow, "B").Value
End If
Else
'Col A is is different--drop down a row in the output
'and plop in the first values
oRow = oRow + 1
NewWks.Cells(oRow, "A").Value = .Cells(iRow, "A").Value
NewWks.Cells(oRow, "B").Value = .Cells(iRow, "B").Value
End If
Next iRow
End With

NewWks.UsedRange.Columns.AutoFit
End Sub

This sorts the original data by column A, then by column B and just goes through
each row looking for differences.

If Col A and col B are the same, it's a duplicate and nothing happens.

If Col A is the same, but col B is different, it appends that value to the
current cell in the output worksheet.

If Col A is different (then we don't care about column B), we just drop down a
row in the output and put the new values in that new row.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


"Susana C via OfficeKB.com" wrote:

Hi,

I have a worksheet with 31,000 rows of data. I would like to use a vlookup
to return all the values listed in column b with its corresponding value is
column A

Colum A Column
B
000000xxc093NEF 0 20050225 Modality
000000xxc093NEF 0 20050225 CMT
000001239619UAL 0 20050126 Visit
000001239619UAL 0 20050126 E & M

I would like it to return:
Column A Column B
000000xxc093NEF 0 20050225 Modality, CMT
000001239619UAL 0 20050126 Visitss, E & M

I have search many threads, but just can't seem to find the one that fits my
need.

Thank you so much!!

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200607/1


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Vlookup

I LOVE YOU GUYS!

Thank you so much for your help, this worked wonderfully!

Dave Peterson wrote:
That's not really what =vlookup() does.

But you could use a macro to do it.

Make sure row 1 has headers in it and I'm assuming that there isn't anything
else in the worksheet besides the stuff in columns A and B.

Option Explicit
Sub testme()

Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim oRow As Long

Set CurWks = Worksheets("sheet1")
Set NewWks = Worksheets.Add
NewWks.Range("a1").Resize(1, 2).Value _
= CurWks.Range("a1").Resize(1, 2).Value

With CurWks
.Range("a:b").Sort key1:=.Range("a1"), order1:=xlAscending, _
key2:=.Range("b1"), order2:=xlAscending, _
header:=xlYes

FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

oRow = 1
For iRow = FirstRow To LastRow
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
If .Cells(iRow, "B").Value = .Cells(iRow - 1, "B").Value Then
'both col A and B are the same, do nothing!
'those values are already taken care of
Else
'Col A is the same, but col B is different
'so just add a comma and that value to the output
NewWks.Cells(oRow, "B").Value _
= NewWks.Cells(oRow, "B").Value & ", " _
& .Cells(iRow, "B").Value
End If
Else
'Col A is is different--drop down a row in the output
'and plop in the first values
oRow = oRow + 1
NewWks.Cells(oRow, "A").Value = .Cells(iRow, "A").Value
NewWks.Cells(oRow, "B").Value = .Cells(iRow, "B").Value
End If
Next iRow
End With

NewWks.UsedRange.Columns.AutoFit
End Sub

This sorts the original data by column A, then by column B and just goes through
each row looking for differences.

If Col A and col B are the same, it's a duplicate and nothing happens.

If Col A is the same, but col B is different, it appends that value to the
current cell in the output worksheet.

If Col A is different (then we don't care about column B), we just drop down a
row in the output and put the new values in that new row.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Hi,

[quoted text clipped - 22 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200607/1



--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLookup a Vlookup adamb2000 Excel Worksheet Functions 4 June 28th 06 10:54 PM
VLOOKUP Problem Ian Excel Discussion (Misc queries) 3 April 6th 06 06:47 PM
Using single cell reference as table array argument in Vlookup CornNiblet Excel Worksheet Functions 3 September 22nd 05 09:15 AM
VLOOKUP Limitations chris_manning Excel Worksheet Functions 2 August 9th 05 06:23 PM
vlookup data hidden within worksheet Excel Worksheet Functions 0 January 26th 05 12:09 PM


All times are GMT +1. The time now is 11:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"