![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Apr 2002
Posts: 19
|
Have existing Row colors from a code am using from "Mudface"
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If UCase(Target) = "e" Then Target.EntireRow.Interior.ColorIndex = 3 If UCase(Target) = "E" Then Target.EntireRow.Interior.ColorIndex = 3 If UCase(Target) = "u" Then Target.EntireRow.Interior.ColorIndex = 8 If UCase(Target) = "U" Then Target.EntireRow.Interior.ColorIndex = 8 If UCase(Target) = "p" Then Target.EntireRow.Interior.ColorIndex = 4 If UCase(Target) = "P" Then Target.EntireRow.Interior.ColorIndex = 4 If UCase(Target) = "w" Then Target.EntireRow.Interior.ColorIndex = 6 If UCase(Target) = "W" Then Target.EntireRow.Interior.ColorIndex = 6 If UCase(Target) = "O" Then Target.EntireRow.Interior.ColorIndex = 46 If UCase(Target) = "o" Then Target.EntireRow.Interior.ColorIndex = 46 If UCase(Target) = "a" Then Target.EntireRow.Interior.ColorIndex = 2 If UCase(Target) = "A" Then Target.EntireRow.Interior.ColorIndex = 2 End Sub Have tried some of the traveling color codes, but they clear the existing color formats as they cross that row. Anymore ideas would be a great plus. Thanks dennisdjones [ This Message was edited by: dennisdjones on 2002-08-12 10:47 ] |
|
|
|
|
|
#2 |
|
MrExcel MVP
Admin Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,617
|
There are two ways of doing this in the thread attached. If your selection is in a colored row using the second method, you'll loose pre-exisiting interior colors. The first method clears all interior colors on the entire sheet.
They are both worksheet event procedures, you'll want to right click on the sheet in question, select view code, and paste one of the procedures in this sheet code module http://www.mrexcel.com/board/viewtop...c=3988&forum=2 Hope this helps. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,368
|
You can use either the Worksheet_SelectionChange or Workbook_SheetSelectionChange events. Something like this:
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Sh.Cells.Interior.ColorIndex = xlNone
If Target.Cells.Count = 1 Then
With Rows(Target.Row).Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End If
End Sub
Hope this helps, rh |
|
|
|
|
|
#4 | |
|
Join Date: Mar 2002
Posts: 1,193
|
Quote:
Two questions : 1.Is it possible that the color-row ended by the last used column and not to column 256 2.I have several colors in my sheet and do not want to delete them. Many thanks for your time |
|
|
|
|
|
|
#5 | ||
|
Join Date: Mar 2002
Posts: 1,193
|
Quote:
Thanks |
||
|
|
|
|
|
#6 |
|
Join Date: Feb 2002
Posts: 3,063
|
Hi mate
i did not really like the code (no offence boys - you know me well enough to know im not having goes) that was close! I could see issues popping up soon enough. see to me colour rows by condition is fine but needs tailoring, OK you want on cell change as the guys have shown this will be only dont by target method, and slow the sheet down a little as it runs the code each time the active cell changes. but what is the far right cell, that is the last always last never to to further right cell, say a to z is always used AB is NEVER used z would be the column im looking for . OK ill try to re write this, have a look at my feed, look at the bottom, i have taken care of this in conditional formating, as you ask here now.. that sort of thing. http://www.mrexcel.com/board/viewtopic
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#7 |
|
MrExcel MVP
Admin Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,617
|
Jack, your link is broken, am curious though. In the interim, I'll stick with a worksheet event, although as Russell mentions, and for multiple sheets, you'll want the Workbook_SheetSelectionChange procedure, which goes in the 'ThisWorkbook' module.
This is a worksheet event, it needs to go in a worksheet module. Right-click on the sheet, view code and paste the code. It won't overwrite any color except index 36: "Mellow Yellow" _________________ Cheers, NateO [ This Message was edited by: NateO on 2002-05-21 15:39 ] |
|
|
|
|
|
#8 |
|
Join Date: Feb 2002
Posts: 3,063
|
Jack being simple try this: put the the required sheet
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Cells.Interior.ColorIndex = 0 With Target.EntireRow.Interior .ColorIndex = 5 End With End Sub
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#9 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,403
|
Quote:
I know you have plenty of information now on a VBA solution. I am proposing here a formula based CONDITIONAL FORMATTING that should meet your requirements. Formula Is ... =and(cell("contents")<>"",row()=cell("row")) ... FORMAT|PATTERN ... color, say, green Please keep in mind I have not tested it thoroughly -- but please report back how it behaves for you and let us take it from there. Regards! _________________ Yogi Anand Edit: Deleted inactive website from hardcoded signature [ This Message was edited by: Yogi Anand on 2003-01-19 13:03 ] |
|
|
|
|
|
|
#10 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,529
|
In line with Jacks code, I use this as a highlighter. Select a cell once and it is colored, re-select it and it is un-colored. You can select as many cells as you want. To color a whole row just select the row header number! You must select out of the current selection then re-select the colored selection to turn off the highlight. The code works on the "View sheet code" page. Hope this also helps. JSW
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) If Not Intersect(Target, Selection) Is Nothing Then If Target.Interior.ColorIndex = 34 Then Target.Interior.ColorIndex = 0 Else Target.Interior.ColorIndex = 34 End If End If End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|