Type Mismatch

maxshiner

Board Regular
Joined
Sep 24, 2014
Messages
71
Getting a Type mismatch error when running this code

Worksheets("Depr").Range("H21") = _
(Worksheets("Depr").Range("D22") / _
Worksheets("Depr").Range("H24"))

Is something wrong with this code or is to something to do with the values in the cells?

Thanks
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
Code:
With Worksheets("Depr")
    .Range("H21").Value = .Range("D22") / .Range("H24")
End With

Just to make it cleaner. You will get two potential errors with this code:

Overflow because of a divide by zerp
Type Mismatch because D22 or H24 is not an integer/double/long/etc.
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,112
Office Version
  1. 365
Platform
  1. Windows
That line is ok on its own. Is there text in the cells?
 

maxshiner

Board Regular
Joined
Sep 24, 2014
Messages
71

ADVERTISEMENT

H21 is annual depreciation (i.e. $) D22 is Recorded value (i.e. $1,175,529.6) H24 is usefulll life (i.e. 40)


In this example the result woul be $29,388.24

Thanks
 

bbott

Well-known Member
Joined
Feb 5, 2010
Messages
2,350
It should work....

Enter these formulas in two empty cells in your worksheet:

=TYPE(D22)
=TYPE(H24)

What do those formulas return?
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,112
Office Version
  1. 365
Platform
  1. Windows
Is that dollar typed into the cell or a format of the cell? If it is typed in there is your problem.
 

maxshiner

Board Regular
Joined
Sep 24, 2014
Messages
71
=TYPE(D22) returns 1 =TYPE(H24) returns #NAME? I will try to format H24 to be a number

The the dollar values are formated. I think I can get it. If not, I will be back. Thanks for allyour help, I really appreciate it.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,549
Messages
5,529,471
Members
409,884
Latest member
Msinmath
Top