What is wrong with this For Each statement?

R

Ryan M-J

it throws "Type Mismatch (13)" on the "for each" line only if the range is
strings, numbers work fine, but I need it to be strings

Dim addresses As String

For Each c In IIf(Range("C3").End(xlDown), Range("C3",
Range("C3").End(xlDown)), Range("C3"))
If addresses <> "" Then
addresses = addresses & ", " & c.Value
Else
addresses = c.Value
End If
Next
 
J

Jim Cone

The first part of the IIF function must evaluate to either True or False.
So, if "Range("C3").End(xlDown)" contains text the function fails.

Give this a try...
Dim addresses As String
Dim c As Range
For Each c In Range("C3", Cells(Rows.Count, 3).End(xlUp))
If addresses <> "" Then
addresses = addresses & ", " & c.Value
Else
addresses = c.Value
End If
Next
--
Jim Cone
Portland, Oregon USA



"Ryan M-J" <Ryan (e-mail address removed)>
wrote in message
it throws "Type Mismatch (13)" on the "for each" line only if the range is
strings, numbers work fine, but I need it to be strings

Dim addresses As String
For Each c In IIf(Range("C3").End(xlDown), Range("C3",
Range("C3").End(xlDown)), Range("C3"))
If addresses <> "" Then
addresses = addresses & ", " & c.Value
Else
addresses = c.Value
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top