ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What is wrong with this For Each statement? (https://www.excelbanter.com/excel-programming/426260-what-wrong-each-statement.html)

Ryan M-J

What is wrong with this For Each statement?
 
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

ryguy7272

What is wrong with this For Each statement?
 
I don't think I've seen an Error 13 before. Does this help?
http://support.microsoft.com/kb/821292

That IIF looks like something from Access-world.
Maybe this will help:
http://www.access-programmers.co.uk/...ad.php?t=88805

Good luck,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Ryan M-J" wrote:

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


Jim Cone[_2_]

What is wrong with this For Each statement?
 
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
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

Ryan M-J[_2_]

What is wrong with this For Each statement?
 
Thanks!
I thought it retuned a cell reference, not the value of the cell.

Ryan
"Jim Cone" wrote:

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
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



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com