PC Review


Reply
Thread Tools Rate Thread

Code for testing whether a cell or row is highlighted?

 
 
=?Utf-8?B?SkBZ?=
Guest
Posts: n/a
 
      28th May 2007
I need something that is to the purpose of:
if the cell is highlighted, copy the row and paste it here.

What is the code for testing whether a cell or row is highlighted?

Thanks.
 
Reply With Quote
 
 
 
 
Otto Moehrbach
Guest
Posts: n/a
 
      28th May 2007
What do you mean by "highlighted". HTH Otto
"J@Y" <(E-Mail Removed)> wrote in message
news:E6624068-25C0-4F23-AC1E-(E-Mail Removed)...
>I need something that is to the purpose of:
> if the cell is highlighted, copy the row and paste it here.
>
> What is the code for testing whether a cell or row is highlighted?
>
> Thanks.



 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      28th May 2007
On May 28, 11:36 am, J@Y <J...@discussions.microsoft.com> wrote:
> I need something that is to the purpose of:
> if the cell is highlighted, copy the row and paste it here.
>
> What is the code for testing whether a cell or row is highlighted?


Public Function CountSpecial(ColorCell As Range, CntRng As Range) As
Long

'This function will count the contents of cells within the CNTRNG
argument that are highlighted and
'NOT HIDDEN with the same background color as that contained
within the COLORCELL range argument.

On Error GoTo CSErrHandler

Dim CurCell As Range
Dim CurColor As Long

CurColor = ColorCell.Interior.ColorIndex
'MsgBox "The current color selected is " &
ColorCell.Interior.ColorIndex
For Each CurCell In CntRng
'check to see if the row is hidden, if it is then skip to
the next cell
If CurCell.EntireRow.Hidden = False Then
If CurCell.Interior.ColorIndex = CurColor Then
CountSpecial = CountSpecial + CurCell
************************************************************************************************
'YOU WOULD ENTER YOUR COPY & PASTE ROUTINE HERE.
************************************************************************************************
End If
End If
Next CurCell
Exit Function
CSErrHandler:

End Function

This will not do all that you are asking, but it will enable you to
identify cells that are highlighted.
Hope that gets you going in the right direction.
Mark

 
Reply With Quote
 
=?Utf-8?B?SkBZ?=
Guest
Posts: n/a
 
      28th May 2007
I see. So there is really no function that identifies the cell as "colored"?
I HAVE to use colorindex (the exact color of the cell) as a parameter?

"Mark" wrote:

> On May 28, 11:36 am, J@Y <J...@discussions.microsoft.com> wrote:
> > I need something that is to the purpose of:
> > if the cell is highlighted, copy the row and paste it here.
> >
> > What is the code for testing whether a cell or row is highlighted?

>
> Public Function CountSpecial(ColorCell As Range, CntRng As Range) As
> Long
>
> 'This function will count the contents of cells within the CNTRNG
> argument that are highlighted and
> 'NOT HIDDEN with the same background color as that contained
> within the COLORCELL range argument.
>
> On Error GoTo CSErrHandler
>
> Dim CurCell As Range
> Dim CurColor As Long
>
> CurColor = ColorCell.Interior.ColorIndex
> 'MsgBox "The current color selected is " &
> ColorCell.Interior.ColorIndex
> For Each CurCell In CntRng
> 'check to see if the row is hidden, if it is then skip to
> the next cell
> If CurCell.EntireRow.Hidden = False Then
> If CurCell.Interior.ColorIndex = CurColor Then
> CountSpecial = CountSpecial + CurCell
> ************************************************************************************************
> 'YOU WOULD ENTER YOUR COPY & PASTE ROUTINE HERE.
> ************************************************************************************************
> End If
> End If
> Next CurCell
> Exit Function
> CSErrHandler:
>
> End Function
>
> This will not do all that you are asking, but it will enable you to
> identify cells that are highlighted.
> Hope that gets you going in the right direction.
> Mark
>
>

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      28th May 2007
Sub colortest()
If ActiveCell.Interior.ColorIndex = xlNone Then
MsgBox ("not colored")
Else
MsgBox ("colored")
End If
End Sub

--
Gary''s Student - gsnu200725
 
Reply With Quote
 
=?Utf-8?B?SkBZ?=
Guest
Posts: n/a
 
      28th May 2007
Great simple solution. Thanks.

"Gary''s Student" wrote:

> Sub colortest()
> If ActiveCell.Interior.ColorIndex = xlNone Then
> MsgBox ("not colored")
> Else
> MsgBox ("colored")
> End If
> End Sub
>
> --
> Gary''s Student - gsnu200725

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      28th May 2007
You are welcome
Simple is always good.
--
Gary''s Student - gsnu200725


"J@Y" wrote:

> Great simple solution. Thanks.
>
> "Gary''s Student" wrote:
>
> > Sub colortest()
> > If ActiveCell.Interior.ColorIndex = xlNone Then
> > MsgBox ("not colored")
> > Else
> > MsgBox ("colored")
> > End If
> > End Sub
> >
> > --
> > Gary''s Student - gsnu200725

 
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
Add a ' in front of all highlighted code in VBA RyanH Microsoft Excel Programming 2 15th Oct 2008 06:01 PM
Having an entire row highlighted as I move from cell to cell Luthdawg Microsoft Excel Misc 8 2nd Oct 2008 05:25 PM
Testing memory cell by cell, and a specific cell ? Skybuck Flying DIY PC 9 24th Jul 2008 09:52 PM
Rename selected (highlighted) sheet with cell contents of sheets in cell A1 transferxxx@gmail.com Microsoft Excel Programming 2 15th Dec 2006 08:41 AM
Highlighted Reference Cell for a Working Cell =?Utf-8?B?TXIuIExvdw==?= Microsoft Excel Worksheet Functions 0 22nd Jun 2006 04:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 AM.