PC Review


Reply
 
 
Martin
Guest
Posts: n/a
 
      31st Dec 2008
Hello,

I have soem code that doesnt quite work properly and was hoping for some
guidance.

I want to colour the first column of the selected row black, so it
highlights to the user which row they are in. Then when the user moves to
another row the first column of the previous cell reverst back to no colour.
Here is the code so far:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lRow As Long

For lRow = 34 To 100
If lRow = ActiveCell.Row Then
Cells(Target.Row, 1).Interior.ColorIndex = 1
Else
Cells(Target.Row, 1).Interior.ColorIndex = xlNone
End If

Next

End Sub

I think the problem is with the line:

If lRow = ActiveCell.Row Then

Can anyone help me?

Thanks in advance.

Martin
 
Reply With Quote
 
 
 
 
Stefi
Guest
Posts: n/a
 
      31st Dec 2008
Maybe you want this sub:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range(Cells(34, 1), Cells(100, 1)).Interior.ColorIndex = xlNone
If Target.Row >= 34 And Target.Row <= 100 Then
Cells(Target.Row, 1).Interior.ColorIndex = 1
End If
End Sub

Regards,
Stefi


„Martin” ezt *rta:

> Hello,
>
> I have soem code that doesnt quite work properly and was hoping for some
> guidance.
>
> I want to colour the first column of the selected row black, so it
> highlights to the user which row they are in. Then when the user moves to
> another row the first column of the previous cell reverst back to no colour.
> Here is the code so far:
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> Dim lRow As Long
>
> For lRow = 34 To 100
> If lRow = ActiveCell.Row Then
> Cells(Target.Row, 1).Interior.ColorIndex = 1
> Else
> Cells(Target.Row, 1).Interior.ColorIndex = xlNone
> End If
>
> Next
>
> End Sub
>
> I think the problem is with the line:
>
> If lRow = ActiveCell.Row Then
>
> Can anyone help me?
>
> Thanks in advance.
>
> Martin

 
Reply With Quote
 
Martin
Guest
Posts: n/a
 
      31st Dec 2008
Thank you for sharing that, it works perfectly and is much more advanced than
my code so it will help to increase my understanding.

Many thanks,

Martin

"JBeaucaire" wrote:

>
> This is the code I use in my sheets to do what you're talking about, it
> always keeps the current row highlighted all the way across the screen.
> Works great for me.
>
> Code:
> --------------------
> Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
> Const cnNUMCOLS As Long = 100
> Const cnHIGHLIGHTCOLOR As Long = 36 'default lt. yellow
> Static rOld As Range
> Static nColorIndices(1 To cnNUMCOLS) As Long
> Dim i As Long
> If Not rOld Is Nothing Then 'Restore color indices
> With rOld.Cells
> If .Row = ActiveCell.Row Then Exit Sub 'same row, don't restore
> For i = 1 To cnNUMCOLS
> .Item(i).Interior.ColorIndex = nColorIndices(i)
> Next i
> End With
> End If
> Set rOld = Cells(ActiveCell.Row, 1).Resize(1, cnNUMCOLS)
> With rOld
> For i = 1 To cnNUMCOLS
> nColorIndices(i) = .Item(i).Interior.ColorIndex
> Next i
> .Interior.ColorIndex = cnHIGHLIGHTCOLOR
> End With
> End Sub
> --------------------
>
> This code would go into the worksheet tab.
>
>
> --
> JBeaucaire
> ------------------------------------------------------------------------
> JBeaucaire's Profile: http://www.thecodecage.com/forumz/member.php?userid=73
> View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45419
>
>

 
Reply With Quote
 
Martin
Guest
Posts: n/a
 
      31st Dec 2008
Stefi, even simpler and works in the row range I need.

Thank you

"Stefi" wrote:

> Maybe you want this sub:
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> Range(Cells(34, 1), Cells(100, 1)).Interior.ColorIndex = xlNone
> If Target.Row >= 34 And Target.Row <= 100 Then
> Cells(Target.Row, 1).Interior.ColorIndex = 1
> End If
> End Sub
>
> Regards,
> Stefi
>
>
> „Martin” ezt *rta:
>
> > Hello,
> >
> > I have soem code that doesnt quite work properly and was hoping for some
> > guidance.
> >
> > I want to colour the first column of the selected row black, so it
> > highlights to the user which row they are in. Then when the user moves to
> > another row the first column of the previous cell reverst back to no colour.
> > Here is the code so far:
> >
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > Dim lRow As Long
> >
> > For lRow = 34 To 100
> > If lRow = ActiveCell.Row Then
> > Cells(Target.Row, 1).Interior.ColorIndex = 1
> > Else
> > Cells(Target.Row, 1).Interior.ColorIndex = xlNone
> > End If
> >
> > Next
> >
> > End Sub
> >
> > I think the problem is with the line:
> >
> > If lRow = ActiveCell.Row Then
> >
> > Can anyone help me?
> >
> > Thanks in advance.
> >
> > Martin

 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      31st Dec 2008
You are welcome! Thanks for the feedback!
Stefi

„Martin” ezt *rta:

> Stefi, even simpler and works in the row range I need.
>
> Thank you
>
> "Stefi" wrote:
>
> > Maybe you want this sub:
> >
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > Range(Cells(34, 1), Cells(100, 1)).Interior.ColorIndex = xlNone
> > If Target.Row >= 34 And Target.Row <= 100 Then
> > Cells(Target.Row, 1).Interior.ColorIndex = 1
> > End If
> > End Sub
> >
> > Regards,
> > Stefi
> >
> >
> > „Martin” ezt *rta:
> >
> > > Hello,
> > >
> > > I have soem code that doesnt quite work properly and was hoping for some
> > > guidance.
> > >
> > > I want to colour the first column of the selected row black, so it
> > > highlights to the user which row they are in. Then when the user moves to
> > > another row the first column of the previous cell reverst back to no colour.
> > > Here is the code so far:
> > >
> > > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> > > Dim lRow As Long
> > >
> > > For lRow = 34 To 100
> > > If lRow = ActiveCell.Row Then
> > > Cells(Target.Row, 1).Interior.ColorIndex = 1
> > > Else
> > > Cells(Target.Row, 1).Interior.ColorIndex = xlNone
> > > End If
> > >
> > > Next
> > >
> > > End Sub
> > >
> > > I think the problem is with the line:
> > >
> > > If lRow = ActiveCell.Row Then
> > >
> > > Can anyone help me?
> > >
> > > Thanks in advance.
> > >
> > > Martin

 
Reply With Quote
 
 
 
Reply

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Row select mode to highlight active row of active cell Bart Fay Microsoft Excel Misc 0 11th May 2010 09:34 PM
getting the selected range and active cell of a non active worksheetsheet GerryGerry Microsoft Excel Programming 7 23rd Sep 2009 05:22 PM
How to make active cell border prominent and keep entire active row selected for better visibility Radhika Microsoft Excel Programming 2 30th Dec 2008 08:51 AM
run macro although blinking cursor is active in an active cell bartman1980 Microsoft Excel Programming 1 20th Dec 2007 11:29 AM
referring to formula in a non active cell from active cell nickname Microsoft Excel Misc 1 21st Jun 2007 12:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.