Run-time error 13 - Type mismatch, when deleting cells

lycrake

New Member
Joined
Jul 29, 2009
Messages
3
Hi there guys

I found a sample of VBA code on these forums, when I type text into one column I want it to put the Time and Date in the next two columns. If I delete the text, I then want it to delete the date and time.

This all works fine, but I get the above error when i'm selecting multiple cells and trying to delete them (containing the date and time), or when i'm trying to copy and paste multiple cells that contain the date and time.

Here is the code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Column Mod 2 = 1 And Target.Row >= 6 Then

        If Target.Value = "" Then
            Target.Offset(0, 1).Value = ""
            Target.Offset(0, 2).Value = ""
        Else
            Target.Offset(0, 1).Value = Date
            Target.Offset(0, 2).Value = Time   
        
End If
End If
End Sub
Any ideas what i'm doing wrong?

It says the error is on the "If Target.Value = "" Then" line

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Target.Column = 1 And Target.Column Mod 2 = 1 And Target.Row >= 6 Then
    For Each c In Target
        If c.Value = "" Then
            c.Offset(0, 1).Value = ""
            c.Offset(0, 2).Value = ""
        Else
            c.Offset(0, 1).Value = Date
            c.Offset(0, 2).Value = Time
        End If
    Next c
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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