PDA

View Full Version : Solved: Reverse code result



ndendrinos
10-20-2008, 02:45 PM
Example:
Using this code I choose A5 and the font in that row turns from regular black Font to Red.Bold
I realize I've made a mistake and I should have chosen A6 instead.
Need the option to click A5 a second time and revert to .Font.ColorIndex = 0 / Selection.Font.Bold = False

Here is the code (by XLD w/thanks)



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

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

With Target.EntireRow.Font

.Bold = True
.ColorIndex = 3
End With
End If
End Sub

the ideal result would be that if I were to click let us say 5 times in A5 without ever coming out of that cell the font would change to: bold red then black then bold red then black then bold red

JKwan
10-20-2008, 02:52 PM
How about

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

With Target.EntireRow.Font

If .Bold Then
.ColorIndex = 0
Else
.ColorIndex = 3
End If
.Bold = Not (.Bold)
End With
End If

you need to move your focus away from the cell and then click back onto the cell, this acts like a toggle.

ndendrinos
10-20-2008, 02:59 PM
Thanks JKwan.
Tried your suggestion and got an error : Compile error / invalid outside procedure (with the word "target" in "If Not Intersect(Target, Range("A:A")) Is Nothing Then" highlighted in blue

P.S. would prefer if possible to the add to the code to be taken when I click in A3 let us say to the adjacent cell B3 (to come out of focus) then click again in A3 to revert to black font.

Bob Phillips
10-20-2008, 03:06 PM
Replace your code with



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

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

With Target.EntireRow.Font

If Target.Font.Bold Then

.Bold = False
.ColorIndex = xlColorIndexNone
Else

.Bold = True
.ColorIndex = 3
End If
End With
End If
End Sub

ndendrinos
10-20-2008, 03:19 PM
Hello again XLD
Tried your suggestion and got this error: Run time 1004 / Unable to set the color index property of the font class

tried going out of focus when the font changed the first time then came back to click again the same cell in column A.

also tried clicking once to change the color the clicking again still in the same cell and again got the same error.
Both ways :.ColorIndex = xlColorIndexNone is highlighted in yellow

ndendrinos
10-20-2008, 03:31 PM
Still testing and I notice that if I come out of focus having changed from black font to red BOLD when I come back then click again that same cell the code errors , the cell remains red BUT this time it is a regular red and not a BOLD red.
In other words half of the desired result appears to have been met

ndendrinos
10-20-2008, 03:48 PM
Got it . Changed the code to

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

With Target.EntireRow.Font

If Target.Font.Bold Then

.Bold = False
.ColorIndex = xlAutomatic
Else

.Bold = True
.ColorIndex = 3
End If
End With
End If

I will add to be taken out of focus (to adjacent cell) and s/b all OK
Thanks again to both of you

Still cannot find the option to mark this post "Solved" is this option not available anymore?

RonMcK
10-20-2008, 07:14 PM
Got it . Changed the code to
If Not Intersect(Target, Range("A:A")) Is Nothing Then

With Target.EntireRow.Font

If Target.Font.Bold Then

.Bold = False
.ColorIndex = xlAutomatic
Else

.Bold = True
.ColorIndex = 3
End If
End With
End If
I will add to be taken out of focus (to adjacent cell) and s/b all OK
Thanks again to both of you

Still cannot find the option to mark this post "Solved" is this option not available anymore?

ndendrinos,

Two things: First, you can 'Solve' your msg by looking on the Thread Tools dropdown and selecting the proper choice. Second, consider clicking the VBA button to use vba tags instead of code tags; I changed your code to use them in the quote.

Cheers!

ndendrinos
10-20-2008, 07:40 PM
Hello Ron, thanks for the follow up.
Not sure what is going on but I did encapsulate as usual the last code I posted with [ code ] ..... [/ Code ] (the proper way not as spaced here) ..... true I did not check my response to see that all was OK. I will next time.
As for the Thread Tools drop down when I click on it I am taken at the bottom of the screen and that's all . I do not get to choose the "mark Solved" like in the past and that is why I question it.
I had the same problem in the thread I posted before that and again I questioned it but did not hear from any one.
Does anyone else have the same problem?

Tried with the same results all Modes (Linear / Hybrid and Threaded)

RonMcK
10-21-2008, 05:20 AM
Hello Ron, thanks for the follow up.
Not sure what is going on but I did encapsulate as usual the last code I posted with [ code ] ..... [/ Code ] (the proper way not as spaced here) ..... true I did not check my response to see that all was OK. I will next time.
As for the Thread Tools drop down when I click on it I am taken at the bottom of the screen and that's all . I do not get to choose the "mark Solved" like in the past and that is why I question it.
I had the same problem in the thread I posted before that and again I questioned it but did not hear from any one.
Does anyone else have the same problem?

Tried with the same results all Modes (Linear / Hybrid and Threaded)
ndendrinos,

I was trying to point out that when you use [ vba ] [/ vba ] tags you get key words highlighted in color in addition getting a box. And, rather than having to type the tags, clicking the VBA button automagically places the tags for you; all you need to do is paste your code between the tags.

Concerning marking a thread 'solved', here is a screen capture showing what I see when I click Thread Tools on a thread of mine.

HTH,