Row highlight??

A

ADK

Is there a way to have Excel highlight a row when you select a cell with the
mouse or arrow key?

or

Is there a way to highlight every other row but not have it print that way?
I know how to fill the cell rows with a color but do not wish to have the
colors/shades print. I just need a way to highlight every other row or at
least the current row where the selected cell is as a visual aid on the
display for easier inputting.

Reason why I don't color fill every other cell: I will be inserting rows in
the future which would mess up the "every other row" method.

I am using Microsoft Excel 2000

Thanks in advance
 
D

Dave Peterson

Chip Pearson has some instructions at:
http://www.cpearson.com/excel/banding.htm
to use conditional formatting to shade every other line.

It works nicely when you insert rows, too.

You'd do:
Select all the cells (ctrl-a (twice in xl2003)
format|conditional formatting
formula is:
=MOD(ROW(),2)=1
and give it a nice format using the pattern tab.

You could use a helper cell to turn it on or off before printing. (I'm using
$a$1).

Formula is:
=AND($A$1<>"",MOD(ROW(),2)=1)

You type something in A1 and the banding comes back. You clear the cell and
they go away (so you can print).
 
A

ADK

Option Explicit
'// Placed in the ThisWorkbook Object

Private Sub Workbook_Open()
Application.OnKey "{RIGHT}", "HighlightRight"
Application.OnKey "{LEFT}", "HighlightLeft"
Application.OnKey "{UP}", "HighlightUp"
Application.OnKey "{DOWN}", "HighlightDown"
Application.OnKey "{DEL}", "DisableDelete"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "{RIGHT}"
Application.OnKey "{LEFT}"
Application.OnKey "{UP}"
Application.OnKey "{DOWN}"
Application.OnKey "{DEL}"
End Sub

Option Explicit
'/////////////////////////////////
'// Original by NateO for aldo ///
'// 24th Jan 2003 ///
'// Amended by IFM ///
'// 28th Jan 2003 ///
'// Amended by Aldo ///
'//
'/////////////////////////////////

'// Placed in a Std Module

Dim strCol As String
Dim iCol As Integer
Dim dblRow As Double

Sub HighlightRight()
HighLight 0, 1
End Sub

Sub HighlightLeft()
HighLight 0, -1
End Sub

Sub HighlightUp()
HighLight -1, 0, -1
End Sub

Sub HighlightDown()
HighLight 1, 0, 1
End Sub

Sub HighLight(dblxRow As Double, iyCol As Integer, Optional dblZ As Double =
0)

'// Amended to highlight Activecell cross intersection
'// Amended as an Alternative to using Condtional Formats
'// As per Aldo thread;
'// http://216.92.17.166/board/viewtopic.php?topic=19239&forum=2&start=20&22

On Error GoTo NoGo
strCol = Mid(ActiveCell.Offset(dblxRow, iyCol).Address, _
InStr(ActiveCell.Offset(dblxRow, iyCol).Address, "$") + 1, _
InStr(2, ActiveCell.Offset(dblxRow, iyCol).Address, "$") - 2)
iCol = ActiveCell.Column
dblRow = ActiveCell.Row

'// If you don't want screen flicker
Application.ScreenUpdating = False

With Range(strCol & ":" & strCol & "," & dblRow + dblZ & ":" & dblRow +
dblZ)
.Select
'// Need to reset here!
Application.ScreenUpdating = True
.Item(dblRow + dblxRow).Activate
End With

NoGo:
End Sub


Sub DisableDelete()
Cells(ActiveCell.Row, ActiveCell.Column).Select
Application.OnKey "{DEL}"
End Sub

Sub ReSet()
Application.OnKey "{RIGHT}"
Application.OnKey "{LEFT}"
Application.OnKey "{UP}"
Application.OnKey "{DOWN}"
End Sub
 
B

Bob Phillips

Here is another way


'----------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'----------------------------------------------------------------
Cells.FormatConditions.Delete
With Target
With .EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
.Interior.ColorIndex = 20
End With
End With
With .EntireColumn
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With .Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
.Interior.ColorIndex = 20
End With
End With

.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 36
End With

End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top