ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Make code apply to more than 1 column (https://www.excelbanter.com/excel-discussion-misc-queries/261691-make-code-apply-more-than-1-column.html)

Cheryl

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

Don Guillett[_2_]

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



Mike H

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


Cheryl

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


Cheryl

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


.


Don Guillett[_2_]

Make code apply to more than 1 column
 

right click sheet tabview codeleft window select worksheetright window
select double_clickcopy your code there..................

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Cheryl" wrote in message
...
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


.



Cheryl

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


.



All times are GMT +1. The time now is 06:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com