A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Make code apply to more than 1 column



 
 
Thread Tools Display Modes
  #1  
Old April 16th, 2010, 04:23 PM posted to microsoft.public.excel.misc
Cheryl
external usenet poster
 
Posts: 364
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
  #2  
Old April 16th, 2010, 04:37 PM posted to microsoft.public.excel.misc
Don Guillett[_2_]
external usenet poster
 
Posts: 607
Default Make code apply to more than 1 column

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


  #3  
Old April 16th, 2010, 05:10 PM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
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  
Old April 16th, 2010, 06:46 PM posted to microsoft.public.excel.misc
Cheryl
external usenet poster
 
Posts: 364
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  
Old April 16th, 2010, 09:52 PM posted to microsoft.public.excel.misc
Cheryl
external usenet poster
 
Posts: 364
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  
Old April 16th, 2010, 10:02 PM posted to microsoft.public.excel.misc
Cheryl
external usenet poster
 
Posts: 364
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


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:11 PM.


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