+ Reply to Thread
Results 1 to 6 of 6

Macro to clear cells

  1. #1
    Esrei
    Guest

    Macro to clear cells

    I need a macro that if I type a value in column N the cells in the same row
    in coloms M,J and K needs to be cleared. This is what I have at the moment
    but I get runtime error 13 Type mismatch. I am just starting to learn myself
    VBA so please help.
    Thanx


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim row As Integer

    row = Target.row
    If Target.Column = "NA" Then
    Cells(row, 10).Clear
    Cells(row, 11).Clear
    Cells(row, 13).Clear
    Cells(row, 14).Clear
    End If
    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: Macro to clear cells

    Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ws_exit:
    Application.EnableEvents = False

    With Target
    If .Column = 14 Then
    .Offset(0,-1).Clear
    .Offset(0,-3).Clear
    .Offset(0,-4).Clear
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Esrei" <[email protected]> wrote in message
    news:[email protected]...
    > I need a macro that if I type a value in column N the cells in the same

    row
    > in coloms M,J and K needs to be cleared. This is what I have at the moment
    > but I get runtime error 13 Type mismatch. I am just starting to learn

    myself
    > VBA so please help.
    > Thanx
    >
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim row As Integer
    >
    > row = Target.row
    > If Target.Column = "NA" Then
    > Cells(row, 10).Clear
    > Cells(row, 11).Clear
    > Cells(row, 13).Clear
    > Cells(row, 14).Clear
    > End If
    > End Sub




  3. #3
    tina
    Guest

    RE: Macro to clear cells

    Hi
    Try
    If Not Range("N:N") Is Nothing Then
    in place of
    If Target.Column = "NA" Then
    Tina
    "Esrei" wrote:

    > I need a macro that if I type a value in column N the cells in the same row
    > in coloms M,J and K needs to be cleared. This is what I have at the moment
    > but I get runtime error 13 Type mismatch. I am just starting to learn myself
    > VBA so please help.
    > Thanx
    >
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim row As Integer
    >
    > row = Target.row
    > If Target.Column = "NA" Then
    > Cells(row, 10).Clear
    > Cells(row, 11).Clear
    > Cells(row, 13).Clear
    > Cells(row, 14).Clear
    > End If
    > End Sub


  4. #4
    tina
    Guest

    RE: Macro to clear cells

    Sorry my suggestion does not work please follows bob advice
    tina

    "tina" wrote:

    > Hi
    > Try
    > If Not Range("N:N") Is Nothing Then
    > in place of
    > If Target.Column = "NA" Then
    > Tina
    > "Esrei" wrote:
    >
    > > I need a macro that if I type a value in column N the cells in the same row
    > > in coloms M,J and K needs to be cleared. This is what I have at the moment
    > > but I get runtime error 13 Type mismatch. I am just starting to learn myself
    > > VBA so please help.
    > > Thanx
    > >
    > >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > Dim row As Integer
    > >
    > > row = Target.row
    > > If Target.Column = "NA" Then
    > > Cells(row, 10).Clear
    > > Cells(row, 11).Clear
    > > Cells(row, 13).Clear
    > > Cells(row, 14).Clear
    > > End If
    > > End Sub


  5. #5
    Bob Phillips
    Guest

    Re: Macro to clear cells

    Tina,

    It would if you just extended it to

    If Not Intersect(Target, Range("N:N")) Is Nothing Then

    but you must also add the event disbaling/re-enabling code that I added.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "tina" <[email protected]> wrote in message
    news:[email protected]...
    > Hi
    > Try
    > If Not Range("N:N") Is Nothing Then
    > in place of
    > If Target.Column = "NA" Then
    > Tina
    > "Esrei" wrote:
    >
    > > I need a macro that if I type a value in column N the cells in the same

    row
    > > in coloms M,J and K needs to be cleared. This is what I have at the

    moment
    > > but I get runtime error 13 Type mismatch. I am just starting to learn

    myself
    > > VBA so please help.
    > > Thanx
    > >
    > >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > Dim row As Integer
    > >
    > > row = Target.row
    > > If Target.Column = "NA" Then
    > > Cells(row, 10).Clear
    > > Cells(row, 11).Clear
    > > Cells(row, 13).Clear
    > > Cells(row, 14).Clear
    > > End If
    > > End Sub




  6. #6
    tina
    Guest

    Re: Macro to clear cells

    Thanks Bob

    "Bob Phillips" wrote:

    > Tina,
    >
    > It would if you just extended it to
    >
    > If Not Intersect(Target, Range("N:N")) Is Nothing Then
    >
    > but you must also add the event disbaling/re-enabling code that I added.
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "tina" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi
    > > Try
    > > If Not Range("N:N") Is Nothing Then
    > > in place of
    > > If Target.Column = "NA" Then
    > > Tina
    > > "Esrei" wrote:
    > >
    > > > I need a macro that if I type a value in column N the cells in the same

    > row
    > > > in coloms M,J and K needs to be cleared. This is what I have at the

    > moment
    > > > but I get runtime error 13 Type mismatch. I am just starting to learn

    > myself
    > > > VBA so please help.
    > > > Thanx
    > > >
    > > >
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > Dim row As Integer
    > > >
    > > > row = Target.row
    > > > If Target.Column = "NA" Then
    > > > Cells(row, 10).Clear
    > > > Cells(row, 11).Clear
    > > > Cells(row, 13).Clear
    > > > Cells(row, 14).Clear
    > > > End If
    > > > End Sub

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1