Code for testing whether a cell or row is highlighted?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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?
 
Sub colortest()
If ActiveCell.Interior.ColorIndex = xlNone Then
MsgBox ("not colored")
Else
MsgBox ("colored")
End If
End Sub
 

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

Back
Top