Macro to select / highlight entire row.


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1  
Unread 28th August 2009, 18:32
Ross's Avatar
Ross
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Macro to select / highlight entire row.
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   


How can I get Excel to select an entire row when I use the "Arrow UP" key or
the "Arrow Down" key?

For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data in
some of the A:Z columns (columns are not consistently filled for all cell
A4:Z4).

This will help the viewer see all of the A4:Z4 cells highlighted (kind of a
custom user input aid).

Many Thanks

Ross

The Code Cage Advertisment
Advertisement
  #2  
Unread 28th August 2009, 18:57
Matthew Herbert's Avatar
Matthew Herbert
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default RE: Macro to select / highlight entire row.

------ Register to get rid of these "In Post" ads! ------


Ross,

I would recommend that you not change the native Excel navigation keys. Why
not create a shortcut (OnKey Method) that calls a macro to select/highlight
the data? (You can tie the SetupShortcut and DestroyShortcut to the workbook
open and close events. Or you can run these however you desire. Also, I
chose Ctrl+q as the shortcut below; you can change the shortcut to be
something you desire, but Ctrl+q is not a native Excel shortcut).

Best,

Matthew Herbert

Option Explicit

Sub SelectCells()
Dim strColStart As String
Dim strColEnd As String
Dim lngRow As Long

strColStart = "A"
strColEnd = "Z"
lngRow = ActiveCell.Row

Range(strColStart & lngRow, strColEnd & lngRow).Select

End Sub

Sub SetupShortcut()
Application.OnKey "^q", "SelectCells"
End Sub

Sub DestroyShortcut()
Application.OnKey "^q"
End Sub

"Ross" wrote:

>
> How can I get Excel to select an entire row when I use the "Arrow UP" key or
> the "Arrow Down" key?
>
> For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
> the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data in
> some of the A:Z columns (columns are not consistently filled for all cell
> A4:Z4).
>
> This will help the viewer see all of the A4:Z4 cells highlighted (kind of a
> custom user input aid).
>
> Many Thanks
>
> Ross


  #3  
Unread 28th August 2009, 19:12
Mike H's Avatar
Mike H
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default RE: Macro to select / highlight entire row.

------ Register to get rid of these "In Post" ads! ------


Ross,

Your question is contradictary. To select the entire row use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveCell.EntireRow.Select
end sub

to select columns A -Z use

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveCell
Range(Cells(.Row, "A"), Cells(.Row, "Z")).Select
End With
End Sub

To instal these right click your sheet tab, view code and paste the code in
on the right

Mike
"Ross" wrote:

>
> How can I get Excel to select an entire row when I use the "Arrow UP" key or
> the "Arrow Down" key?
>
> For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
> the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data in
> some of the A:Z columns (columns are not consistently filled for all cell
> A4:Z4).
>
> This will help the viewer see all of the A4:Z4 cells highlighted (kind of a
> custom user input aid).
>
> Many Thanks
>
> Ross


The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #4  
Unread 28th August 2009, 19:20
Rick Rothstein's Avatar
Rick Rothstein
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Macro to select / highlight entire row.

------ Register to get rid of these "In Post" ads! ------


How about code that puts a border around the current row? Give this a try.
Right click the tab at the bottom of the worksheet you want to have this
functionality, select View Code from the popup menu that appears and then
copy/paste the following into the code window that opened up...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo Whoops
Application.ScreenUpdating = False
Cells.Borders.LineStyle = xlLineStyleNone
Target.EntireRow.BorderAround Weight:=xlMedium
Whoops:
Application.ScreenUpdating = True
End Sub

By the way, this will work for *any* method of moving to a new cell (or
range of cells), not just for the arrow keys.

--
Rick (MVP - Excel)


"Ross" <Ross@discussions.microsoft.com> wrote in message
news:79FF14F0-BAE3-499D-86C4-57955C848DF9@microsoft.com...
>
> How can I get Excel to select an entire row when I use the "Arrow UP" key
> or
> the "Arrow Down" key?
>
> For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
> the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data
> in
> some of the A:Z columns (columns are not consistently filled for all cell
> A4:Z4).
>
> This will help the viewer see all of the A4:Z4 cells highlighted (kind of
> a
> custom user input aid).
>
> Many Thanks
>
> Ross



  #5  
Unread 28th August 2009, 19:22
L. Howard Kittle's Avatar
L. Howard Kittle
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Re: Macro to select / highlight entire row.

------ Register to get rid of these "In Post" ads! ------


Hi Ross,

Try this in the worksheet Module. Right click the sheet tab and select View
Code, copy and paste in the large white area.

Select any cell between A2 to Z25 and note the highlighting. Can be
modified to a different range size and a color of choice.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Data As Range
Dim i As Integer
Dim k As Integer
i = 1
k = ActiveCell.Column()
Set Data = Range("A2:Z25")

Data.Interior.ColorIndex = xlNone

If ActiveCell.Row < 2 Or ActiveCell.Row > 25 Or _
ActiveCell.Column < 1 Or ActiveCell.Column > 26 Then
Exit Sub
End If

ActiveCell.Offset(0, -(k - i)). _
Resize(1, 26).Interior.ColorIndex = 35

End Sub

HTH
Regards,
Howard

"Ross" <Ross@discussions.microsoft.com> wrote in message
news:79FF14F0-BAE3-499D-86C4-57955C848DF9@microsoft.com...
>
> How can I get Excel to select an entire row when I use the "Arrow UP" key
> or
> the "Arrow Down" key?
>
> For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
> the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data
> in
> some of the A:Z columns (columns are not consistently filled for all cell
> A4:Z4).
>
> This will help the viewer see all of the A4:Z4 cells highlighted (kind of
> a
> custom user input aid).
>
> Many Thanks
>
> Ross




  #6  
Unread 28th August 2009, 19:22
Ross's Avatar
Ross
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default RE: Macro to select / highlight entire row.

------ Register to get rid of these "In Post" ads! ------


Perfect!

Thanks Mike

"Mike H" wrote:

> Ross,
>
> Your question is contradictary. To select the entire row use
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> ActiveCell.EntireRow.Select
> end sub
>
> to select columns A -Z use
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> With ActiveCell
> Range(Cells(.Row, "A"), Cells(.Row, "Z")).Select
> End With
> End Sub
>
> To instal these right click your sheet tab, view code and paste the code in
> on the right
>
> Mike
> "Ross" wrote:
>
> >
> > How can I get Excel to select an entire row when I use the "Arrow UP" key or
> > the "Arrow Down" key?
> >
> > For Example, if the cursor has selected Cell A3 and I "Arrow Down" to A4,
> > the cursor would then select the ENTIRE A4 ROW (this spreadsheet has data in
> > some of the A:Z columns (columns are not consistently filled for all cell
> > A4:Z4).
> >
> > This will help the viewer see all of the A4:Z4 cells highlighted (kind of a
> > custom user input aid).
> >
> > Many Thanks
> >
> > Ross


The Code Cage Advertisment
Advertisement
New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
entire, highlight, macro, row, select

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 06:10.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University