You don't have to fill an array to accomplish what you need. I added one
line to the code I gave you earlier which will do what your second question
is asking. You may need to adjust the sheet name. I assumed that the sheet
you are copying too has a header.
Option Explicit
Public Sub ConcatenateEmail()
Dim myString As String
Dim r As Long
For r = 4 To Cells(Rows.Count, "G").End(xlUp).Row
If IsError(Cells(r, "G")) Then
Range("F4:F" & r).Value = Sheets("Sheet2").Range("A2:A" &
r).Value
Exit For
Else
myString = myString & Cells(r, "G").Value & ","
End If
Next r
myString = Left(myString, Len(myString) - 1)
Range("A2") = myString
End Sub
Hope this helps! If so, then click "YES" below. Thanks!
--
Cheers,
Ryan
"RyanH" wrote:
> This code will loop from row 4 to last row in Col. G
>
> Option Explicit
>
> Public Sub ConcatenateEmail()
>
> Dim myString As String
> Dim r As Long
>
> For r = 4 To Cells(Rows.Count, "G").End(xlUp).Row
> If IsError(Cells(r, "G")) Then
> Exit For
> Else
> myString = myString & Cells(r, "G").Value & ","
> End If
> Next r
>
> myString = Left(myString, Len(myString) - 1)
> Range("A2") = myString
>
> End Sub
>
> Hope this helps! If so please let me know by clicking "YES" below.
> --
> Cheers,
> Ryan
>
>
> "John Pierce" wrote:
>
> > I need to make the following code work for a variable number of rows
> > and stop when it reaches a #VALUE! error.
> >
> >
> > Public Sub ConcatenateEmail()
> > Dim myString As String
> > Dim r As Long
> >
> > myString = ""
> >
> > For r = 4 To 585
> > myString = myString & Cells(r, "G") & ","
> > Next r
> >
> > myString = Left(myString, Len(myString) - 1)
> > Range("A2") = myString
> > End Sub
> >
|