I have a code on one of my worksheets that automatically deletes records when called upon to do.
Unfortunately, when I create a new record on that sheet i.e. paste, I get the following error:
Run-time error '13':
Type mismatch
I only get this error when I try to paste values to multiple cells in the table.
Here is the problem, it only gives the error when I try to paste multiple values, when I paste to a single cell, there is no problem
Once I debug, excel returns that the problem is with the line colored in red below.
This is a problem as we have many rows of data and if the user cant' just copy and paste from source, it would be too cumbersome a tool.
And just to clarify, I am pasting into an existing table, simply overwriting existing data.
Unfortunately, when I create a new record on that sheet i.e. paste, I get the following error:
Run-time error '13':
Type mismatch
I only get this error when I try to paste values to multiple cells in the table.
Here is the problem, it only gives the error when I try to paste multiple values, when I paste to a single cell, there is no problem
Once I debug, excel returns that the problem is with the line colored in red below.
This is a problem as we have many rows of data and if the user cant' just copy and paste from source, it would be too cumbersome a tool.
And just to clarify, I am pasting into an existing table, simply overwriting existing data.
Code:
Public Sub Worksheet_Change(ByVal Target As Range) [COLOR=#008000]'_Change creates the variable as a target, transferred as a value to "ProjectName"[/COLOR]
Dim ans As Integer
[B][COLOR=#ff0000] If Target.Column = 2 And Target.Row > 1 And Target.Value = "" Then[/COLOR][/B]
ans = MsgBox("Are you sure you want to Delete......This cannot Be Undone !!!", vbYesNo)
If ans = vbYes Then
With Application
.EnableEvents = False ' freeze WorkSheetChange event since you're about to UNDO a change
.Undo ' undo the change
ProjectName = Target.Value ' assign the deleted-undone value in to YYY
Rows(ActiveCell.Row).EntireRow.Delete ' delete that row
.EnableEvents = True ' re-enable all events
End With
MsgBox ProjectName & " has been deleted." ' now you have that value in ProjectName
End If
End If
DeleteRows (ProjectName) 'Gives sub-routine "DeleteRows" the company name
End Sub