Rachel Chia
Rachel Chia

Reputation: 259

For each next mismatch error

I'm currently trying to convert some data into the units I want. There are only two units; mils & microns. The combo box allows the user to choose which unit they want the data to be in. If the data is not in the unit the user wants then it will need to convert.

I'm trying to test this out:
The scenario now is the data is in mils and I need to convert it to microns. However it has been giving me error of type mismatch for the second data on line: rngx.value = rngx.value / y

Dim cx As range
Dim rng As range
Dim cy As range
Dim rngx As range
Const y As Double = 25.4
If unit <> Sheet1.ComboBox1.value Then '------> Data 1 
   If Sheet1.ComboBox1.value = " Mils" Then '---> from mils to microns 
     Set cx = Sheet9.range("E2", Sheet9.range("E2").End(xlDown))
     For Each rng In cx
     rng.value = rng.value * y
     Next rng
   Else
     Set cx = Sheet9.range("E2", Sheet9.range("E2").End(xlDown))'---> Microns to mils 
     For Each rng In cx
     rng.value = rng.value / y
     Next rng
   End If
End If

If unit <> Sheet1.ComboBox2.value Then '-------> Data 2 
   If Sheet1.ComboBox2.value = " Mils" Then'---> from mils to microns 
    Set cy = Sheet9.range("I2", Sheet9.range("I2").End(xlDown))
     For Each rngx In cy
     rngx.value = rngx.value * y
     Next rngx
  Else
    Set cy = Sheet9.range("I2", Sheet9.range("I2").End(xlDown))'---> Microns to mils 
    For Each rngx In cy
     rngx.value = rngx.value / y
     Next rngx
  End If
End If

Upvotes: 0

Views: 56

Answers (1)

Hank
Hank

Reputation: 187

This error basically means that: variable or property isn't of the correct type.

For example, a variable that requires an integer value can't accept a string value unless the whole string can be recognized as an integer.

Solution:

1) make sure all your values returned are numbers

2) make sure none of your values returned are empty as such "" << string type

this should solve your issue

Upvotes: 1

Related Questions