Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

Ok VBA prgs....

I need this solution:

A person left clicks on a cell that already has text in it. I need
that cell to (1) change color, and (2) generate a value (in a different
cell) because the person clicked in the text cell (can be value of 1 or
0).

For example, in Column A, in cells 1-12 I write in the months of the
year. If a person clicks on the cell containing "March" (cell A3) I
want that cell to change to the color yellow, and in cell B3 the number
"1" is entered.

Any ideas?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how do I: click in cell and make it change color?

Jason,

Add this code to the worksheet code module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A12")) Is Nothing Then
Range("A1:A12").Interior.ColorIndex = xlColorIndexNone
Target.Interior.ColorIndex = 6
Target.Offset(0, 1) = 1
End If

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jasonsweeney " wrote in
message ...
Ok VBA prgs....

I need this solution:

A person left clicks on a cell that already has text in it. I need
that cell to (1) change color, and (2) generate a value (in a different
cell) because the person clicked in the text cell (can be value of 1 or
0).

For example, in Column A, in cells 1-12 I write in the months of the
year. If a person clicks on the cell containing "March" (cell A3) I
want that cell to change to the color yellow, and in cell B3 the number
"1" is entered.

Any ideas?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

Thank you very much that is helpful.

But I need the color to remain "on" once clicked, but if you click th
same cell again, then the color turns "off" (and the number als
dissapears).

Thus, in my example, if you select March, the cell turns yellow an
Cell B3 gets a "1." Then you select "January". Now there should b
two yellow cells, both with a "1" next to it. Now I click on "March
again and it turns back to no color, leaving only January yellow with
"1" next to it

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how do I: click in cell and make it change color?

Jason,

Okay try this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A12")) Is Nothing Then
If Target.Offset(0,1) = 1 Then
Target.Interior.Colorindex = xlColorindexNone
Target.Offset(0,1).Value = ""
Else
Target.Interior.ColorIndex = 6
Target.Offset(0, 1) = 1
End If
End If

End Sub



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jasonsweeney " wrote in
message ...
Thank you very much that is helpful.

But I need the color to remain "on" once clicked, but if you click the
same cell again, then the color turns "off" (and the number also
dissapears).

Thus, in my example, if you select March, the cell turns yellow and
Cell B3 gets a "1." Then you select "January". Now there should be
two yellow cells, both with a "1" next to it. Now I click on "March"
again and it turns back to no color, leaving only January yellow with a
"1" next to it.


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

Perfect. Thanks a million.


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

One problem:

I incorporated your code into the application I am working on....but
now I get an "Error 13" when I try and select more than one cell.....

still using my example, When I select March AND February at the same
time in one selection, I get an error 13.


---
Message posted from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

Another issue: My boss now wants this solution:

Click on cell A1 once and it produces a "1" in cell B1
Click on cell A1 a second time, and it products a "2" in cell B1
Click on cell A1 a third time, and it produces a "3" in cell B1
Click on cell A1 a fourth tme, and it produces a "4" in cell B1

*** Click on cell A1 a fifth time, and it resets the cell to "".

Thus, a person can cycle through the numbners 1-4 by simply clicking o
cell A1 4 times....I think I have to select a different cell after eac
cycle so the person has to click BACK on cell A1 to trigger....thus th
last code line will be <Range("A3").select

Any help would be greatly appreciated

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I: click in cell and make it change color?

Based on my description above, here is what I have tried....the proble
is that when you click on the target cell once, it instantly cycle
through all the numbers without stopping....thus I need to arrest th
cycle after one click....any help would be great.

[In cells B1:B12 I entered the months of the year]
_____________________________________

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("B1:B12")) Is Nothing Then

If Target.Offset(0, 1) = "" Then
Target.Offset(0, 1).Value = 1
Target.Offset(0, -1).Select

If Target.Offset(0, 1) = 1 Then
Target.Offset(0, 1).Value = 2
Target.Offset(0, -1).Select

If Target.Offset(0, 1) = 2 Then
Target.Offset(0, 1).Value = 3
Target.Offset(0, -1).Select

If Target.Offset(0, 1) = 3 Then
Target.Offset(0, 1).Value = 4
Target.Offset(0, -1).Select

If Target.Offset(0, 1) = 4 Then
Target.Offset(0, 1).Value = ""
Target.Offset(0, -1).Select


End If
End If
End If
End If
End If
End If

End Su

--
Message posted from http://www.ExcelForum.com

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
Theme color doesn't change when I click it? Rachey Excel Worksheet Functions 1 March 5th 08 09:30 PM
can u make a text in a cell to blink , or change it's color? kbee Excel Worksheet Functions 2 February 15th 08 07:40 PM
make cell color change if requirements are met? PMLACC Excel Discussion (Misc queries) 2 July 14th 06 10:01 PM
Stumped: If a cell contains a formula, can you make text color automatically change? qwopzxnm Excel Worksheet Functions 7 April 5th 06 04:07 AM
Change cell back color on click Dave Peterson Excel Discussion (Misc queries) 0 January 24th 05 10:50 PM


All times are GMT +1. The time now is 12:27 PM.

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

About Us

"It's about Microsoft Excel"