Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Help. It should be simple, but it is not.

I have a two column list. I am trying to find a way to extract information
from one cell and add it to another based on criterial from the cell in the
first column. I need it to only put information in the last row for the Matl
No. when there are more than one material number. A Matl No. might show up
any number of times. I am having real trouble with the logic for this.

I think it should first evaluate the count for each Matl No. (** I don't
know how to do that except from the Data, Subtotal menu.)
Then run a loop through all the records in that count.

Can anybody help me with this programming dilemma?

Ex.
Desired Result
Matl No. Asset No. Assets
1234 15A65
1234 16B23
1234 16F56 15A65, 16B23, 16F56
1489 25D54 25D54
1389 35Y64
1389 75Y62 35Y64, 75Y62

Mat
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Help. It should be simple, but it is not.

Give this code a try...

Sub Test()
Dim rngToSearch As Range
Dim rng As Range
Dim strAccumulate As String
Dim wks As Worksheet

Set wks = ActiveSheet
With wks
Set rngToSearch = .Range(.Range("A2"), .Cells(Rows.Count,
"A").End(xlUp))
End With

For Each rng In rngToSearch
If rng.Value = rng.Offset(1, 0).Value Then
If strAccumulate = "" Then
strAccumulate = rng.Offset(0, 1).Value
Else
strAccumulate = strAccumulate & ", " & rng.Offset(0, 1).Value
End If
Else
If strAccumulate = "" Then
rng.Offset(0, 2).Value = rng.Offset(0, 1).Value
Else
rng.Offset(0, 2).Value = strAccumulate & ", " &
rng.Offset(0, 1).Value
End If
strAccumulate = ""
End If
Next rng
End Sub

--
HTH...

Jim Thomlinson


"wrightlife11" wrote:

I have a two column list. I am trying to find a way to extract information
from one cell and add it to another based on criterial from the cell in the
first column. I need it to only put information in the last row for the Matl
No. when there are more than one material number. A Matl No. might show up
any number of times. I am having real trouble with the logic for this.

I think it should first evaluate the count for each Matl No. (** I don't
know how to do that except from the Data, Subtotal menu.)
Then run a loop through all the records in that count.

Can anybody help me with this programming dilemma?

Ex.
Desired Result
Matl No. Asset No. Assets
1234 15A65
1234 16B23
1234 16F56 15A65, 16B23, 16F56
1489 25D54 25D54
1389 35Y64
1389 75Y62 35Y64, 75Y62

Mat

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Help. It should be simple, but it is not.

Hi Mat, You can also give this code a try. It very similar to Jim's code.
Good Luck and enjoy...

Rick

Sub TestIt()
Dim lrow As Long
Dim x As Long
Dim allAsst As String
Dim ws As Worksheet

Set ws = ActiveSheet
lrow = ws.Range("a2").End(xlDown).Row

With ws
For x = 2 To lrow
If .Cells(x + 1, 1) = .Cells(x, 1) Then
allAsst = IIf(allAsst = "", .Cells(x, 2), allAsst & ", " & .Cells(x,
2))
Else
.Cells(x, 3) = IIf(allAsst = "", .Cells(x, 2), allAsst & ", " &
..Cells(x, 2))
allAsst = ""
End If
Next x
End With
End Sub



"Jim Thomlinson" wrote in message
...
Give this code a try...

Sub Test()
Dim rngToSearch As Range
Dim rng As Range
Dim strAccumulate As String
Dim wks As Worksheet

Set wks = ActiveSheet
With wks
Set rngToSearch = .Range(.Range("A2"), .Cells(Rows.Count,
"A").End(xlUp))
End With

For Each rng In rngToSearch
If rng.Value = rng.Offset(1, 0).Value Then
If strAccumulate = "" Then
strAccumulate = rng.Offset(0, 1).Value
Else
strAccumulate = strAccumulate & ", " & rng.Offset(0,

1).Value
End If
Else
If strAccumulate = "" Then
rng.Offset(0, 2).Value = rng.Offset(0, 1).Value
Else
rng.Offset(0, 2).Value = strAccumulate & ", " &
rng.Offset(0, 1).Value
End If
strAccumulate = ""
End If
Next rng
End Sub

--
HTH...

Jim Thomlinson


"wrightlife11" wrote:

I have a two column list. I am trying to find a way to extract

information
from one cell and add it to another based on criterial from the cell in

the
first column. I need it to only put information in the last row for the

Matl
No. when there are more than one material number. A Matl No. might show

up
any number of times. I am having real trouble with the logic for this.

I think it should first evaluate the count for each Matl No. (** I don't
know how to do that except from the Data, Subtotal menu.)
Then run a loop through all the records in that count.

Can anybody help me with this programming dilemma?

Ex.
Desired Result
Matl No. Asset No. Assets
1234 15A65
1234 16B23
1234 16F56 15A65, 16B23, 16F56
1489 25D54 25D54
1389 35Y64
1389 75Y62 35Y64, 75Y62

Mat



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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Make it more simple or intuitive to do simple things Vernie Charts and Charting in Excel 1 March 16th 05 04:01 AM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 05:00 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"