![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Microsoft Office support MS Office support forum |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
Highlight active row in Excel
I would like an easy way to highlight an active row in Excel. I'm not really proficient in Visual Basic, so if that's the only way, your specific direction would be greatly appreciate. Thanks in advace.
|
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Hi
Other than manually highlighting the row, you will have to use VBA. There are several very involved methods, but one easy one is to pop up a message box asking you to confirm that you want the row highlighted. Otherwise, every time you click on any row it will be highlighted. Will you want to remove the highlight at any time? Will you be highlighting more than one row?
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
highlight row in excel
thanks for responding. i would not want to highlight more than 1 row at a time and a pop up message would be okay. basically, whatever the easiest way would be, would work for me. But like I said, i've only played around with VBasic a little. Thanks for your continued help.
Todd |
|
|
|
|
|
#4 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Hi Todd
See if this works for you. This code uses the Worksheet Selection Change Event - when you click on a cell in rows 1 to 20 a pop up will appear asking if you want to highlight the entire row. If you say YES the entire row is coloured red - if you say NO nothing happens. You can change the colour to suit. I've used a cut off of the first 20 rows but you can change that as well. Copy the code below, then right click the relevant sheet tab, select 'View Code' and paste the code to the right pane. Press Alt+F11 to return to Excel. Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myReply
Dim myRow As Integer
myRow = Target.Row
If myRow > 20 Then Exit Sub
myReply = MsgBox("Do you want to highlight this row", vbYesNo)
If myReply = vbNo Then Exit Sub
ActiveCell.EntireRow.Interior.ColorIndex = 3
End Sub
HTH Regards
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
Active Row Highlight
howdy. Thanks so much for your help on this. Can a couple of things be changed? Firstly, can you write it so the active row is highlighted automatically without a prompt? Maybe something like "do you want the active row highlighted on this sheet at all times" but i'll leave that to you. Basically, if i'm on row 1, only row 1 is highlighted, on row 5, only row 5 is highlighted, etc. Also, can we change the color to say, yellow [or tell me the value # for the colors]
Thanks a ton for your help. Todd |
|
|
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
Active Row Highlight
howdy. Thanks so much for your help on this. Can a couple of things be changed? Firstly, can you write it so the active row is highlighted automatically without a prompt? Maybe something like "do you want the active row highlighted on this sheet at all times" but i'll leave that to you. Basically, if i'm on row 1, only row 1 is highlighted, on row 5, only row 5 is highlighted, etc. Also, can we change the color to say, yellow [or tell me the value # for the colors]
Also, will there be any easy way to do this each time? Macro? or do i need to copy and paste the VB language each time I open a spreadsheet where I desire the highlighting? Thanks a ton for your help. Todd |
|
|
|
|
|
#7 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Hi Todd
No problem on the changes, but I'd like to clarify some things first. If I take out the pop up, as things are, it will highlight every row when you click on a cell in that row. So you will need to "unhighlight" (if there is such a word!) a row already highlighted before the next one is highlighted? An Event procedure such as this relates specifically to the sheet in question - you can't 'call' this procedure from another file. Regards
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#8 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
highlite row
Well, unfortunately, either way would be kind of unpractical. I often use sheets with a couple hundred rows with data [hence looking for a way to make numbers more easily read on the active row]. Having to either click okay each time in addition to having to unhighlite the previous row would become somewhat time consuming. C'mon, you're working your magic wonderfully! Isn't there another way?? You're so close....Thanks....
Last edited by tg93135; 01-17-2006 at 03:14 PM. |
|
|
|
|
|
#9 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Todd
Try this - it goes in the ThisWorkbook Module and will therefore work for any sheet in the workbook. Add Code to ThisWorkbook Module 1. Right click on the Excel icon beside ‘File’ on the Menu Bar. 2. Choose 'View Code' from the menu 3. Paste the code to the right pane. Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range) Static OldRng As Range On Error Resume Next Target.EntireRow.Interior.ColorIndex = 6 OldRange.EntireRow.Interior.ColorIndex = xlColorIndexNone Set OldRng = Target End Sub Regards
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#10 (permalink) |
|
Registered User
Join Date: Aug 2005
Posts: 11
OS: xp
|
highlite row
soooo close, however the "old" range isn't going back to "non-highlited"
and just to clarify, I would need to paste the VB language into the code window each time I open a spreadsheet i want to use this on, right? or is there a shortcut? THANKS THANKS |
|
|
|
|
|
#11 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Apologies - code blooper. Use this
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range) Static OldRng As Range On Error Resume Next Target.EntireRow.Interior.ColorIndex = 6 OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone Set OldRng = Target End Sub Other than that it works fine.
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#13 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
No shortcut I'm afraid Todd.
You'll need to copy and paste it for each workbook. But once in the workbook it will work for each sheet in that workbook without any further copy/paste. Regards
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#15 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Not really. The code is an Event code - it relies on a change on the worksheet to fire. Macros generally require some kind of action from the user - clicking a command button, for example - perhaps possible but unlikely. Certainly way beyond my knowledge. It won't be much effort to do a simple copy and paste - perhaps copy the code to a Word for suture reference?
Regards
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
|
|
#17 (permalink) |
|
Registered User
Join Date: Jul 2009
Posts: 1
OS: WinXP
|
Re: Highlight active row in Excel
the problem i faced while using the code was although the cells are highlighted but when you copy a cell and try to drag down copy in the column you are in, the copied cell is deselected and you can't paste. Glaswegian, can you provide an alternate code which takes care of this issue?
|
|
|
|
|
|
#18 (permalink) |
|
Registered User
Join Date: Aug 2009
Posts: 1
OS: xp
|
Re: Highlight active row in Excel
I have been using the below code and I have not had problems using the copy command or drag down copy. The code does highlight the active row and column, not just the row.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim RngRow As Range Dim RngCol As Range Dim RngFinal As Range Dim Row As Long Dim Col As Long Cells.Interior.ColorIndex = xlNone Row = Target.Row Col = Target.Column Set RngRow = Range("A" & Row, Target) Set RngCol = Range(Cells(1, Col), Target) Set RngFinal = Union(RngRow, RngCol) RngFinal.Interior.ColorIndex = 6 End Sub |
|
|
|
|
|
#19 (permalink) |
|
Registered User
Join Date: Oct 2009
Posts: 2
OS: vista
|
Re: Highlight active row in Excel
i tried using these codes and i can't excel to recognize the modules. it almost seems like it has something to do with the 'byvaltarget as range'. i even tried creating my own macro and then just pasting this code in, and the macro disappears and just won't run. any ideas?
|
|
|
|
|
|
#20 (permalink) |
|
Moderator/ Rangemaster TSF Academy; Analyst, Security Team; Oor Wullie; TSF Surgeon and Resident Comic
|
Re: Highlight active row in Excel
Hi and welcome.
the code must be pasted into the Sheet module. One way to do this is to right click the sheet tab and select 'View Code' - when the VBE opens, that's where you post the code.
__________________
Iain - Defender of the Haggis and all things Scottish. I don't help by PM - post in the Forums. ![]() ![]() PC Safety & Security::PC running a bit slow?::Donate::Photographers Corner |
|
|
|
![]() |
| Thread Tools | |
|
|