Run time error 13 type mismatch

stig20

New Member
Joined
Mar 4, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have problem with VBA macro in excel. I see error 13 type mismatch, after try to import data to excel sheet.

First macro import data from several files from the specified folder (*.xls excel files), but it stop with error at: "If Target.Column = 1 And Target.Row > 1 And Target <> "" Then"

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row > 1 And Target <> "" Then
    Application.EnableEvents = False
    If Right(Target, 1) <> "\" Then Target = Target & "\"
    On Error GoTo e
    If Dir(Target, vbDirectory) = "" Then
        Target.Font.Color = vbRed
        MsgBox "Wrong path, correct.", vbCritical, "Attention"
        Target.Select
    Else
        Target.Font.Color = vbBlue
    End If
    Application.EnableEvents = True
End If
Exit Sub
e:
If Err = 52 Then
    Target.Font.Color = vbRed
    MsgBox "Wrong path, correct.", vbCritical, "Attention"
    Target.Select
End If
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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