Type Mismatch error

docam84

New Member
Joined
May 29, 2007
Messages
23
Hello,

I am having trouble trying to prevent this error from popping up and I was wondering if anyone could give me any clue as to why this is occurring.

My code checks to see if a cell contains a certain status, such as Approved or Rejected. If the status is Approved, then the procedure copies the row and pastes it onto a different worksheet within the same workbook. The row is then deleted (in the ChangeStatus procedure).

Here is my code:

<code>
Dim strClient As String

<font color = "blue">On Error GoTo ErrHandler</font>

<font color = "blue">If Not Intersect</font>(Target, Range("L2:L500")) Is Nothing Then

     strClient = Target.Offset(0, -10).Value

     Call ChangeStatus(Target.Row, Target.Value)

End If

Exit Sub

ErrHandler:

' // statements for error handler

Exit Sub
</code>
 
If you mean rorya's suggestion regarding turning off events then that's not quite right.

That wouldn't prevent the error occurring when you delete a row.

The problem is that if you are deleting a row then the Target is the whole row and that can't be put in a string.

A string can only hold a single value.:)
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hmm, I see. So, how would I circumvent this issue? Should I set <code> Target = Nothing </code> if it selects the entire row?
 
Upvote 0
No.

You need to check the no of cells in Target.
Code:
If Target.Count > 1 Then Exit Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,875
Members
449,476
Latest member
pranjal9

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