Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default need assistance with some find or lookup related code...

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default need assistance with some find or lookup related code...

If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & " " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

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

hshayh0rn wrote:

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default need assistance with some find or lookup related code...

Wow Dave! That worked really well. Now I don't want to be really greedy but
here is the next and final step I need to accomplish. I have another sheet
that contains the following data type:

A B C D

J. Doe Junk Data w377004 AA1 BIY KKI
WQQ
T. Smith Junk Data w377008 TIY NNU FFQ
FFT

I would like to have a macro look at the data in the sheet you just helped
me with looking for the numbers on this sheet in column C and if that number
exists on the other sheet then bring in the data from that sheet and put it
in column E.

We don't need to think about opening that other sheet and looking for the
data. I can have the person using the sheet simply paste the data in it's raw
format into this sheet and run the macro you just helped me with. I think
what I would do though is combine the two sets of code so that it's one
action for the user to complete.

"Dave Peterson" wrote:

If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & " " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

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

hshayh0rn wrote:

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default need assistance with some find or lookup related code...

I would just fill in the cell with a formula:

(You do have a leading w in column C of this data, though...)

=vlookup(mid(c1,2,255),sheet2!a:b,2,false)
or if those other values are numbers (not numbers treated like text)
=vlookup(--mid(c1,2,255),sheet2!a:b,2,false)

You could even look for errors:

=if(iserror(vlookup(...)),"",vlookup(...))

You can record a macro when you build the formula you want, copy it down the
range and edit|copy, followed by edit|Paste special values.

Then just include that in your original code????


hshayh0rn wrote:

Wow Dave! That worked really well. Now I don't want to be really greedy but
here is the next and final step I need to accomplish. I have another sheet
that contains the following data type:

A B C D

J. Doe Junk Data w377004 AA1 BIY KKI
WQQ
T. Smith Junk Data w377008 TIY NNU FFQ
FFT

I would like to have a macro look at the data in the sheet you just helped
me with looking for the numbers on this sheet in column C and if that number
exists on the other sheet then bring in the data from that sheet and put it
in column E.

We don't need to think about opening that other sheet and looking for the
data. I can have the person using the sheet simply paste the data in it's raw
format into this sheet and run the macro you just helped me with. I think
what I would do though is combine the two sets of code so that it's one
action for the user to complete.

"Dave Peterson" wrote:

If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & " " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

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

hshayh0rn wrote:

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default need assistance with some find or lookup related code...

When I use the first formula I get a result in the cell I typed the formula
in of: #N/A

"Dave Peterson" wrote:

I would just fill in the cell with a formula:

(You do have a leading w in column C of this data, though...)

=vlookup(mid(c1,2,255),sheet2!a:b,2,false)
or if those other values are numbers (not numbers treated like text)
=vlookup(--mid(c1,2,255),sheet2!a:b,2,false)

You could even look for errors:

=if(iserror(vlookup(...)),"",vlookup(...))

You can record a macro when you build the formula you want, copy it down the
range and edit|copy, followed by edit|Paste special values.

Then just include that in your original code????


hshayh0rn wrote:

Wow Dave! That worked really well. Now I don't want to be really greedy but
here is the next and final step I need to accomplish. I have another sheet
that contains the following data type:

A B C D

J. Doe Junk Data w377004 AA1 BIY KKI
WQQ
T. Smith Junk Data w377008 TIY NNU FFQ
FFT

I would like to have a macro look at the data in the sheet you just helped
me with looking for the numbers on this sheet in column C and if that number
exists on the other sheet then bring in the data from that sheet and put it
in column E.

We don't need to think about opening that other sheet and looking for the
data. I can have the person using the sheet simply paste the data in it's raw
format into this sheet and run the macro you just helped me with. I think
what I would do though is combine the two sets of code so that it's one
action for the user to complete.

"Dave Peterson" wrote:

If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & " " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

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

hshayh0rn wrote:

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default need assistance with some find or lookup related code...

Use the second formula to test for errors.

=if(iserror(vlookup(...)),"",vlookup(...))



hshayh0rn wrote:

When I use the first formula I get a result in the cell I typed the formula
in of: #N/A

"Dave Peterson" wrote:

I would just fill in the cell with a formula:

(You do have a leading w in column C of this data, though...)

=vlookup(mid(c1,2,255),sheet2!a:b,2,false)
or if those other values are numbers (not numbers treated like text)
=vlookup(--mid(c1,2,255),sheet2!a:b,2,false)

You could even look for errors:

=if(iserror(vlookup(...)),"",vlookup(...))

You can record a macro when you build the formula you want, copy it down the
range and edit|copy, followed by edit|Paste special values.

Then just include that in your original code????


hshayh0rn wrote:

Wow Dave! That worked really well. Now I don't want to be really greedy but
here is the next and final step I need to accomplish. I have another sheet
that contains the following data type:

A B C D

J. Doe Junk Data w377004 AA1 BIY KKI
WQQ
T. Smith Junk Data w377008 TIY NNU FFQ
FFT

I would like to have a macro look at the data in the sheet you just helped
me with looking for the numbers on this sheet in column C and if that number
exists on the other sheet then bring in the data from that sheet and put it
in column E.

We don't need to think about opening that other sheet and looking for the
data. I can have the person using the sheet simply paste the data in it's raw
format into this sheet and run the macro you just helped me with. I think
what I would do though is combine the two sets of code so that it's one
action for the user to complete.

"Dave Peterson" wrote:

If your data is already sorted by column A:

Option Explicit
Sub testme()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value Then
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value & " " & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

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

hshayh0rn wrote:

I have a spread sheet that is set-up similar to this:

377004 AA1
377004 BI2
377004 HH6
377008 DFE
377009 AA1
377009 DFE
377025 BI2
377025 CCI

I need a function or some VB code that would create a new cell with the code
in column A only listed once and then the codes in column B concatenated
together (with spaces between each code). It should look something like this:

377004 AA1 BI2 HH6
377008 DFE
377009 AA1 DFE
377025 BI2 CCI

Anyone have some ideas?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
help needed with lookup and related functions EdStevens Excel Worksheet Functions 3 August 19th 09 10:00 PM
Lookup related question Craig Excel Worksheet Functions 1 June 23rd 09 04:48 PM
Lookup value and return with all related data help_0616 Excel Discussion (Misc queries) 0 July 17th 08 03:46 AM
lookup related with defined name KrunoG Excel Worksheet Functions 0 February 24th 06 01:42 PM
Finding the Max of a related Value Lookup Cav Excel Worksheet Functions 4 November 23rd 05 02:53 PM


All times are GMT +1. The time now is 12:49 PM.

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

About Us

"It's about Microsoft Excel"