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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

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,717
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,717
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,601
Messages
5,838,300
Members
430,537
Latest member
Antonio11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top