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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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.
 
Upvote 0
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
 
Upvote 0
It should work....

Enter these formulas in two empty cells in your worksheet:

=TYPE(D22)
=TYPE(H24)

What do those formulas return?
 
Upvote 0
Is that dollar typed into the cell or a format of the cell? If it is typed in there is your problem.
 
Upvote 0
=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.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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
Back
Top