PDA

View Full Version : [SOLVED] Type Mismatch in Excel 2003



mgh_mgharish
02-19-2005, 12:57 PM
A code like cells(1,4).End(xlUp)
works fine in Excel XP but not in 2003


Sub a()
For i = 2 To Cells(1, 4).End(xlUp)
If (Cells(i, 4).Value = 3.9) Then
Range(Cells(i, 4), Cells(i, 4).End(xlToRight)).Copy Cells(i - 1, 6)
Rows(i).Delete
End If
Next
End Sub


What may be the problem? What should be done?

zilpher
02-19-2005, 01:23 PM
Cells(1, 4).End(xlUp) will return a range object, yet you are using this in a For Next loop. You probably want to add .Row on the end, or maybe .Value, depends what property you want to use of the cell that Cells(1, 4).End(xlUp) returns.

You also probably want to do some checks to make sure you do get a number, and gracefully exit if you don't.

HTH

mgh_mgharish
02-19-2005, 01:40 PM
Yes.. but that works great in XP :doh:

Anne Troy
02-19-2005, 09:15 PM
Hi, mgh. I have run your code in both 2002 and 2003, and I do not get an error in either. ?

Jacob Hilderbrand
02-19-2005, 09:29 PM
What is the error message that you get?

mgh_mgharish
02-19-2005, 11:27 PM
Type Mismatch
Run time error

mgh_mgharish
02-19-2005, 11:36 PM
OK.. I have solved that.. That depends on the data in D1 cell..
If it is a string, it gives error

Jacob Hilderbrand
02-19-2005, 11:38 PM
Ahh. Try this.


If Val(Cells(i, 4).Value) = 3.9 Then

Anne Troy
02-19-2005, 11:39 PM
Cool.

Yo, mgh. I saw a really cool macro you put over there at that other site that would make a nice KB entry here. You know...the one where we "force" the user to enter dates into a cell?

Also, you can mark your own thread solved here by using Thread Tools at the top of this Q.

mgh_mgharish
02-19-2005, 11:51 PM
Thanks one and all :hi: