Share via

Type Mismatch when deleting data

Anonymous
2010-12-08T21:30:26+00:00

Can anyone tell me why if I clear contents of a group of cells I get a Type Mismatch and the only way I can get the code working again is to exit Excel and come back in.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Target.HasFormula Then

    Application.EnableEvents = False

    Select Case Target.Column

    Case Is = 2, 3, 5: Target = UCase(Target)

'or strconv

    Case Else

    End Select

    Application.EnableEvents = True

End If

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2010-12-08T21:57:35+00:00

It does for me. Are you sure that you copied the code into the worksheet module?

If so, do the following:

Activate the Visual Basic Editor (Alt+F11)

Activate the Immediate window (Ctrl+G)

Type the following line then press Enter:

Application.EnableEvents = True

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-12-09T00:02:39+00:00

    Thanks for your help. Not sure why it did not work the first time but is working great now.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-12-08T21:48:11+00:00

    It does not seem to capitalize the text that is typed into the cell

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2010-12-08T21:43:18+00:00

    UCase applies to a single value only, so you can't use it for a multi-cell target. Try this:

    Private Sub Worksheet_Change(ByVal Target As Range)

        Dim rng As Range

        Application.EnableEvents = False

        For Each rng In Target.Cells

            If Not rng.HasFormula Then

                Select Case rng.Column

                    Case 2, 3, 5

                        rng= UCase(rng)

                End Select

            End If

        Next rng

        Application.EnableEvents = True

    End Sub

    Was this answer helpful?

    0 comments No comments