#1   Report Post  
Esrei
 
Posts: n/a
Default 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   Report Post  
Bob Phillips
 
Posts: n/a
Default

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" wrote in message
...
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   Report Post  
tina
 
Posts: n/a
Default

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   Report Post  
tina
 
Posts: n/a
Default

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   Report Post  
Bob Phillips
 
Posts: n/a
Default

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" wrote in message
...
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   Report Post  
tina
 
Posts: n/a
Default

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I pause a macro to select specific cells lee Excel Worksheet Functions 1 April 2nd 05 02:11 PM
Macro to delete data in 'green' cells only Steve Excel Worksheet Functions 7 March 19th 05 01:40 PM
repeat macro formula to all cells dave glynn Excel Discussion (Misc queries) 8 March 10th 05 08:42 PM
Clear Contents - NonBold cells Steve Excel Discussion (Misc queries) 3 February 13th 05 11:36 PM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 02:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"