Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Concatenate Values with VBA

I have items in column G on Sheet1 and I am trying to find all
corresponding customer names on Sheets("sheet1"). On this sheet with
the customers the item numbers are in column a and the customers are
in column B. An item may be listed more then once on the
Sheets("Sheet1") becasue there are more then one customer listed. I
am trying to go through each item in Sheet1 and concatenate all
customers that have that item number from Sheets("Sheet1"). Sheet1
and Sheets("Sheet1") are two different sheets in the same workbook.
Here is the code I have so far. It tells me I do not have a loop in
place. Huh?

Thanks,
Jay

Sub findLast()
Dim i
Dim lstRow As Long
Dim strResult As String
Dim Concat As String
Dim TargetCell As Range

lstRow = Range("g65536").End(xlUp).Row + 1

For Each i In Sheet1.Range("G4:G" & lstRow)
Dim rngFound As String
On Error GoTo nXtI
rngFound = Sheets("Sheet1").Range("A:A").Find(i.Value, _
LookAt:=xlWhole, LookIn:=xlFormulas, MatchCase:=True).Address
MsgBox (rngFound)

Dim myC As String
myC = Sheets("Sheet1").Range("A2:A65536").Find(i.Value, , , , , _
xlPrevious).Address
MsgBox (myC)


Set TargetCell = Sheets("Sheet1").Range(rngFound)


Do
If TargetCell.Row < Sheets("Sheet1").Range(myC).Row + 1
Then
strResult = TargetCell.Offset(0, 1).Value
Else
If TargetCell.Row = Range(myC).Row Then
Concat = TargetCell.Offset(0, 1).Value
End If
Concat = strResult & ", " & Concat
Loop Until TargetCell.Row = Sheets("Sheet1").Range(myC).Row

MsgBox (Concat)

nXtI:
Next i
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Concatenate Values with VBA

Jay, You're short of an End If. See line in your code below starting with **.

"jlclyde" wrote:

... It tells me I do not have a loop in
place. Huh?

Thanks,
Jay

Sub findLast()
Dim i
Dim lstRow As Long
Dim strResult As String
Dim Concat As String
Dim TargetCell As Range

lstRow = Range("g65536").End(xlUp).Row + 1

For Each i In Sheet1.Range("G4:G" & lstRow)
Dim rngFound As String
On Error GoTo nXtI
rngFound = Sheets("Sheet1").Range("A:A").Find(i.Value, _
LookAt:=xlWhole, LookIn:=xlFormulas, MatchCase:=True).Address
MsgBox (rngFound)

Dim myC As String
myC = Sheets("Sheet1").Range("A2:A65536").Find(i.Value, , , , , _
xlPrevious).Address
MsgBox (myC)


Set TargetCell = Sheets("Sheet1").Range(rngFound)


Do
If TargetCell.Row < Sheets("Sheet1").Range(myC).Row + 1
Then
strResult = TargetCell.Offset(0, 1).Value
Else
If TargetCell.Row = Range(myC).Row Then
Concat = TargetCell.Offset(0, 1).Value

** End If
End If
Concat = strResult & ", " & Concat
Loop Until TargetCell.Row = Sheets("Sheet1").Range(myC).Row

MsgBox (Concat)

nXtI:
Next i
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Concatenate Values with VBA

On Oct 1, 10:10*am, Lionel H
wrote:
Jay, You're short of an End If. See line in your code below starting with **.





"jlclyde" wrote:
... *It tells me I do not have a loop in
place. *Huh?


Thanks,
Jay


Sub findLast()
* * Dim i
* * Dim lstRow As Long
* * Dim strResult As String
* * Dim Concat As String
* * Dim TargetCell As Range


* * lstRow = Range("g65536").End(xlUp).Row + 1


* * For Each i In Sheet1.Range("G4:G" & lstRow)
* * * * Dim rngFound As String
* * On Error GoTo nXtI
* * rngFound = Sheets("Sheet1").Range("A:A").Find(i.Value, _
* * * * LookAt:=xlWhole, LookIn:=xlFormulas, MatchCase:=True).Address
* * MsgBox (rngFound)


* * Dim myC As String
* * myC = Sheets("Sheet1").Range("A2:A65536").Find(i.Value, , , , , _
* * * * xlPrevious).Address
* * MsgBox (myC)


* * Set TargetCell = Sheets("Sheet1").Range(rngFound)


* * * * Do
* * * * * * If TargetCell.Row < Sheets("Sheet1").Range(myC).Row + 1
Then
* * * * * * * * strResult = TargetCell.Offset(0, 1).Value
* * * * * * Else
* * * * * * * * If TargetCell.Row = Range(myC).Row Then
* * * * * * * * * * Concat = TargetCell.Offset(0, 1).Value


** * * * * * * * *End If



* * * * * * End If
* * * * * * Concat = strResult & ", " & Concat
* * * * Loop Until TargetCell.Row = Sheets("Sheet1").Range(myC).Row


* * * * MsgBox (Concat)


nXtI:
* * Next i
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -

- Show quoted text -


There was some more tweaking that I needed to do, but you were right
as soon as I addded the end if it was off and runnign again.
Thanks,
Jay
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
CONCATENATE on separated values [email protected] New Users to Excel 4 August 16th 07 12:28 AM
Concatenate values IF() Nikki Excel Worksheet Functions 21 May 12th 07 11:06 PM
Concatenate with the formula values Narendra Excel Worksheet Functions 2 March 9th 07 06:07 AM
Concatenate values dan Excel Worksheet Functions 2 August 14th 06 11:03 PM
concatenate values/texts corresp. to a searched repeated value/tex K.S.Warrier Excel Worksheet Functions 5 December 18th 04 08:17 AM


All times are GMT +1. The time now is 04:21 PM.

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"