Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Type Mismatch

I receive a 'type mismatch' when trying to use the following line of code to
check the contents of cells and then assign a constant to the variable 'item'.


If Range("n1").Value < "" And Range("n2:n50").Value = "" Then item = 1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Type Mismatch

On Sat, 21 Jan 2006 19:17:02 -0800, "Mike"
wrote:

I receive a 'type mismatch' when trying to use the following line of code to
check the contents of cells and then assign a constant to the variable 'item'.


If Range("n1").Value < "" And Range("n2:n50").Value = "" Then item = 1


I think the problem has to do with trying to get the Value property of a
multicell Range object. I think you have to loop through the range to do what
you are trying to do.


--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Type Mismatch

In this case, you don't need to loop if you only want all the cells (n2:n50)
to be empty as the second condition
If Range("n1").Value < "" And Application.CountA(Range("n2:n50")) = 0 Then
item = 1






--
Regards,
Tom Ogilvy


"Ron Rosenfeld" wrote in message
...
On Sat, 21 Jan 2006 19:17:02 -0800, "Mike"


wrote:

I receive a 'type mismatch' when trying to use the following line of code

to
check the contents of cells and then assign a constant to the variable

'item'.


If Range("n1").Value < "" And Range("n2:n50").Value = "" Then item = 1


I think the problem has to do with trying to get the Value property of a
multicell Range object. I think you have to loop through the range to do

what
you are trying to do.


--ron



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Type Mismatch

On Sat, 21 Jan 2006 23:00:10 -0500, "Tom Ogilvy" wrote:

In this case, you don't need to loop if you only want all the cells (n2:n50)
to be empty as the second condition
If Range("n1").Value < "" And Application.CountA(Range("n2:n50")) = 0 Then
item = 1


That's true.

I was being more general.


--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Type Mismatch

On Sat, 21 Jan 2006 23:00:10 -0500, "Tom Ogilvy" wrote:

In this case, you don't need to loop if you only want all the cells (n2:n50)
to be empty as the second condition
If Range("n1").Value < "" And Application.CountA(Range("n2:n50")) = 0 Then
item = 1


That's true.

I was being more general and neglected to focus on the OP's issue.
--ron


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Type Mismatch

Hi Mike,

Try;

'=============
Public Sub Tester003()
Dim myItem As Long

If Range("n1").Value < "" And _
Application.CountA(Range("n2:n50")) = 0 Then myItem = 1
MsgBox myItem

End Sub
'<<============

BTW, I changed Item to myItem because Item ia a reserved word.


---
Regards,
Norman



"Mike" wrote in message
...
I receive a 'type mismatch' when trying to use the following line of code
to
check the contents of cells and then assign a constant to the variable
'item'.


If Range("n1").Value < "" And Range("n2:n50").Value = "" Then item = 1



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Type Mismatch

Worked great, thanks Norman

"Norman Jones" wrote:

Hi Mike,

Try;

'=============
Public Sub Tester003()
Dim myItem As Long

If Range("n1").Value < "" And _
Application.CountA(Range("n2:n50")) = 0 Then myItem = 1
MsgBox myItem

End Sub
'<<============

BTW, I changed Item to myItem because Item ia a reserved word.


---
Regards,
Norman



"Mike" wrote in message
...
I receive a 'type mismatch' when trying to use the following line of code
to
check the contents of cells and then assign a constant to the variable
'item'.


If Range("n1").Value < "" And Range("n2:n50").Value = "" Then item = 1




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
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
type mismatch--how to fix rroach Excel Discussion (Misc queries) 2 July 14th 05 06:23 PM
Type Mismatch Raman325[_4_] Excel Programming 1 June 29th 05 06:51 PM
Type Mismatch Jack Schitt Excel Programming 2 September 3rd 04 11:55 AM


All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"