Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default I need a macro that fills in a cell with an "X" if I click it.

I'm trying to create a macro that I can apply to worksheets where I need to
classify terms into one or more categories. It would be great if I could just
click in the cells that represent the category for each term instead of
clicking and then hitting X.

Thanks,
Ivan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default I need a macro that fills in a cell with an "X" if I click it.

Hi Ivan,

Try:

'=============
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range

Set Rng = Me.Range("A1:A100") '<<=== CHANGE
Set Rng = Intersect(Rng, Target)

If Not Rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
Rng.Value = "X"
End If

XIT:
Application.EnableEvents = True
End Sub
'<<=============

This is worksheet event code and should be pasted into
the worksheets's code module (not a standard module
and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

---
Regards,
Norman


"Ivan Laars" wrote in message
...
I'm trying to create a macro that I can apply to worksheets where I need
to
classify terms into one or more categories. It would be great if I could
just
click in the cells that represent the category for each term instead of
clicking and then hitting X.

Thanks,
Ivan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default I need a macro that fills in a cell with an "X" if I click it.

Norman-
This worked like a charm and introduced me to a whole new world of Excel
functionality! Thanks 10^6

-Ivan

"Norman Jones" wrote:

Hi Ivan,

Try:

'=============
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range

Set Rng = Me.Range("A1:A100") '<<=== CHANGE
Set Rng = Intersect(Rng, Target)

If Not Rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
Rng.Value = "X"
End If

XIT:
Application.EnableEvents = True
End Sub
'<<=============

This is worksheet event code and should be pasted into
the worksheets's code module (not a standard module
and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

---
Regards,
Norman


"Ivan Laars" wrote in message
...
I'm trying to create a macro that I can apply to worksheets where I need
to
classify terms into one or more categories. It would be great if I could
just
click in the cells that represent the category for each term instead of
clicking and then hitting X.

Thanks,
Ivan




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default I need a macro that fills in a cell with an "X" if I click it.

Ivan

To have the code operate on all worksheets in the workbook you could alter
Norman's code and place it in the Thisworkbook module.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As _
Range)

Dim Rng As Range

Set Rng = ActiveSheet.Range("A1:A100") '<<=== CHANGE
Set Rng = Intersect(Rng, Target)

If Not Rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
Rng.Value = "X"
End If

XIT:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Mon, 9 Apr 2007 20:47:48 +0100, "Norman Jones"
wrote:

Hi Ivan,

Try:

'=============
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range

Set Rng = Me.Range("A1:A100") '<<=== CHANGE
Set Rng = Intersect(Rng, Target)

If Not Rng Is Nothing Then
On Error GoTo XIT
Application.EnableEvents = False
Rng.Value = "X"
End If

XIT:
Application.EnableEvents = True
End Sub
'<<=============

This is worksheet event code and should be pasted into
the worksheets's code module (not a standard module
and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.

---
Regards,
Norman


"Ivan Laars" wrote in message
...
I'm trying to create a macro that I can apply to worksheets where I need
to
classify terms into one or more categories. It would be great if I could
just
click in the cells that represent the category for each term instead of
clicking and then hitting X.

Thanks,
Ivan



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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Control" plus "click" doesn't allow me to select multiple cells Ken Cooke New Users to Excel 0 September 25th 06 04:46 PM
Automatically click "Update Links" & "Continue" paulharvey[_13_] Excel Programming 0 June 3rd 06 05:35 PM
Worksheets("Brackets").DropDowns("Game10").Click Tony_VBACoder Excel Programming 5 January 28th 05 04:41 AM
commnd button - when i rt click, "assign macro" isnt an option... kevin[_3_] Excel Programming 1 November 12th 04 09:52 PM


All times are GMT +1. The time now is 07:08 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"