Substraction of cell General type value

luolovepi

Board Regular
Joined
Jun 9, 2011
Messages
116
Hi all,

I have two worksheets in different workbook, and when some conditions are satisfied, I will substract the value of Range("J" & cell.Row) in desSheet by the value of Range("J" & cell.Row) in Pr worksheet.
The variable "cell" indicates a selected cell.
The full version of code is as below:
Code:
With desSheet
        For Each cell In Range("F4", Range("F" & Rows.count).End(xlUp))
            For i = 1 To 22
                If cell.Value = Trans_Part(i) Then
                    'check whether quantity is the same
                    If .Range("J" & cell.Row).Value = Pr.Range("I" & i).Value Then
                        'delete the entire row
                        .Range("A" & cell.Row & ":N" & cell.Row).Delete
                    Else
                        'substract current quantity by the amount this row just submitted
                        .Range("J" & cell.Row).Value = CInt(.Range("J" & cell.Row).Value) - CInt(Pr.Range("I" & i).Value)
                    End If
                End If
            Next i
        Next cell
    End With

Now I receive an error message "Type mismatch" over the line:
Code:
.Range("J" & cell.Row).Value = CInt(.Range("J" & cell.Row).Value) - CInt(Pr.Range("I" & i).Value)

Could you pls help me to find out the bug and solve this problem?

Thank you very much!

yours sincerely,
lolo^^
 
Last edited:
Hi Sektor,

Thank you. I made some changes in other places and then the error disappears. But i don't understand why missing of value update leads to error here...

Best regards,
lolo^-^
Then you try to convert non-numeric data into Integer here:

Code:
...CInt(.[COLOR=red]Range("J" & cell.Row)[/COLOR].Value) - CInt([COLOR=red]Pr.Range("I" & i)[/COLOR].Value)
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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