PDA

View Full Version : Alter Code to show value in column 'A"



BENSON
09-17-2009, 05:31 AM
I found the code below in this forum, I would like to amend it that it will also show as well as the cell address that meets the test the stock item in colum "A" ie if cell "C3" is conditional formated red it would return the value of "A3" as well as the cell address

Thanks

[VCode]
Sub CF()

Dim cel As Range
Dim rng As Range
Dim myOp As Long
Dim myCell As Range
Dim myColour As Long, msg

Set rng = Sheets("24HR Summary").Range("A4:AJ12")
For Each cel In rng

On Error Resume Next
If cel.FormatConditions.Count > 0 Then

If cel.Value > cel.FormatConditions(1).Formula1 Then

msg = msg & vbNewLine & cel.Address
End If
End If

myColour = 0
myOp = 0
Next cel

MsgBox msg
Set cel = Nothing
Set rng = Nothing
Set myCell = Nothing

End Sub
[/Code]

nst1107
09-17-2009, 09:02 AM
Seems simple enough. Just customize the line 'msg = msg & ...' to make it return whatever you want. E.g.:msg = msg & vbNewLine & cel.Address & " = " & cel.Value

BENSON
09-17-2009, 08:32 PM
Thanks for the reply, I have placed it into my code as I would have also need the high lighted cells value at some stage in designing my spread sheet. However I need help in returning the names of the items listed in collum "A" on the same row as any high lighted cells.



Sub CF()

Dim cel As Range
Dim rng As Range
Dim myOp As Long
Dim myCell As Range
Dim myColour As Long, msg

Set rng = Sheets("24HR Summary").Range("c12:AJ12")
For Each cel In rng

On Error Resume Next
If cel.FormatConditions.Count > 0 Then

If cel.Value > cel.FormatConditions(1).Formula1 Then

msg = msg & vbNewLine & cel.Address & vbNewLine & cel.Address & " = " & cel.Value
End If
End If

myColour = 0
myOp = 0
Next cel

MsgBox msg
Set cel = Nothing
Set rng = Nothing
Set myCell = Nothing

End Sub

mdmackillop
09-19-2009, 05:30 AM
Can you post a sample workbook?

hyzhaozhong
09-20-2009, 07:38 AM
CELLS(CEL.ROW,1)

Is this cell you want?