Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default Make code apply to more than 1 column

I am using this code to insert X in a column with a mouse click. I need this
to apply to other column as well. How do I change this code?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 5 Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Make code apply to more than 1 column

Hi,

How about this which now does columns A,B & E. Change ot it match the
columns you want

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A:A,B:B,E:E")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Cheryl" wrote:

I am using this code to insert X in a column with a mouse click. I need this
to apply to other column as well. How do I change this code?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 5 Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default Make code apply to more than 1 column

Thank You Mike it works!!

"Mike H" wrote:

Hi,

How about this which now does columns A,B & E. Change ot it match the
columns you want

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A:A,B:B,E:E")) Is Nothing Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Cheryl" wrote:

I am using this code to insert X in a column with a mouse click. I need this
to apply to other column as well. How do I change this code?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 5 Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default Make code apply to more than 1 column

You are correct a double right mouse click would be better. How do I do that
change?

"Don Guillett" wrote:

Are you SURE you want this with a SELECTION change? Maybe a double click
instead.

or target.column = 12

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Cheryl" wrote in message
...
I am using this code to insert X in a column with a mouse click. I need
this
to apply to other column as well. How do I change this code?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 5 Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
End If
End Sub


.



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default Make code apply to more than 1 column

I am sorry my in reply to you I meant doulbe left mouse click.

"Don Guillett" wrote:

Are you SURE you want this with a SELECTION change? Maybe a double click
instead.

or target.column = 12

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Cheryl" wrote in message
...
I am using this code to insert X in a column with a mouse click. I need
this
to apply to other column as well. How do I change this code?

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 5 Then
If Len(Trim(Target.Value)) = 0 Then
Target.Value = "X"
Else
Target.ClearContents
End If
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
alter code to apply to range (links cells w/ row insertions) purplec0ws Excel Discussion (Misc queries) 1 November 10th 09 11:19 AM
Problem undstanding how to apply a code Brenda Excel Discussion (Misc queries) 4 October 21st 08 07:55 PM
=COUNTIF & how to make it apply to consecutive cells gretchen Excel Worksheet Functions 2 July 24th 08 06:15 PM
how do I apply changes I make on one sheet to other sheets? Anne Excel Discussion (Misc queries) 2 December 19th 07 09:57 PM
make custom header and footer in excel apply to all worksheets Alexandra Excel Discussion (Misc queries) 1 May 27th 05 06:11 PM


All times are GMT +1. The time now is 08:15 PM.

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"