View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Lionel H Lionel H is offline
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