Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

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
What's wrong with this if statement? Karen Excel Discussion (Misc queries) 5 July 19th 08 04:54 PM
can someone please tell me what i did wrong with this if statement? unclescrooge Excel Programming 2 November 12th 07 12:36 PM
IF Statement help please - again - got it wrong last time! Alan Davies Excel Worksheet Functions 2 May 12th 06 12:28 PM
wts wrong with this statement Jason Excel Worksheet Functions 2 February 24th 06 02:26 PM
What is wrong with this IF statement? need help. AC man Excel Discussion (Misc queries) 4 January 11th 06 03:29 PM


All times are GMT +1. The time now is 06:53 AM.

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"