# Type Mismatch

#### maxshiner

##### Board Regular
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.

#### bbott

##### Well-known Member
That code works fine. What's in the cells?

#### NeonRedSharpie

##### Well-known Member
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
That line is ok on its own. Is there text in the cells?

#### maxshiner

##### Board Regular

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
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
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
=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.

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.

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.

### Which adblocker are you using?

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

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