FAO Ron Rosenfeld

S

Sam Harman

Hi Ron and thanks for your last post....that worked a treat.

Sorry it took so long to thank you but I have been working away and
not had a chance to get back on the newsgroup...

I have one more small question. Do you remember you wrote some code
which highlighted the top three values as follows. Top value
highlighted yellow and red font, 2nd top highlighted green and red
font and third top highlighted green and red font (See below for code)

My question is this, I can now do this for retrospective dates using
your code which combined the date and time fields but can I also do it
for more than one column at a time. For example, I have 10 columns
which I would like to apply the top three macro to and currently have
to do the same thing for each column. I.e select the times, then
select a value in the column. Is it all possible to amend the code so
that when I select a time, i can then select more than one column for
the macro to be run on? The columns are not always adjacent.

As always your consideration and help is much appreciated

Regards

Sam

------------------------------------------------------------------------------

This is the code you originally provided and which I am using:



Sub Color3SPRNew()
Dim rTimes As Range, rValues As Range, c As Range
Dim APOffset As Long
Dim tTimes() As Variant, dPVals() As Double
Dim collTime As Collection, collColQ As Collection
Dim bLowest As Boolean
Dim i As Long, j As Long

On Error Resume Next

Set rTimes = Application.InputBox(Prompt:="Select the Times", _
Default:=Selection.Address, Type:=8)
If rTimes Is Nothing Then Exit Sub

Set rValues = Application.InputBox("Select a cell in the column of
Values", Type:=8)
If rValues Is Nothing Then Exit Sub

On Error GoTo 0

bLowest = IIf(MsgBox("Lowest 4?", vbYesNo) = vbYes, True, False)

APOffset = rValues.Column - rTimes.Column

'Unique list of times
Set collTime = New Collection
On Error Resume Next
For Each c In rTimes
collTime.Add Item:=c.Value, Key:=CStr(c.Value)
Next c
On Error GoTo 0

ReDim tTimes(0 To collTime.Count - 1, 0 To 2)
For i = 0 To collTime.Count - 1
tTimes(i, 0) = collTime(i + 1)
Next i

'unique list of rValues values for each time
For i = 0 To UBound(tTimes, 1)
Set collColQ = New Collection
On Error Resume Next
For Each c In rTimes
If c.Value = tTimes(i, 0) Then
With c.Offset(columnoffset:=APOffset)
If bLowest = True Then collColQ.Add
Item:=CDbl(.text), Key:=CStr(.text)
If bLowest = False And .Value <> 0 Then
collColQ.Add Item:=CDbl(.text), Key:=CStr(.text)
End With
End If
Next c
On Error GoTo 0
If collColQ.Count > 0 Then
ReDim dPVals(0 To collColQ.Count - 1)
For j = 0 To UBound(dPVals)
dPVals(j) = collColQ(j + 1)
Next j
End If
With WorksheetFunction
If bLowest Then
tTimes(i, 1) = .Small(dPVals, .Min(UBound(dPVals) + 1,
3))
tTimes(i, 2) = .Min(dPVals)
Else
tTimes(i, 1) = .Large(dPVals, .Min(UBound(dPVals) + 1,
3))
tTimes(i, 2) = .Max(dPVals)
End If

End With
Next i

'color the cells
For i = 0 To UBound(tTimes, 1)
For Each c In rTimes
If c.Value = tTimes(i, 0) Then
With c.Offset(columnoffset:=APOffset)
If bLowest = False Then
Select Case CDbl(.text)
Case Is = tTimes(i, 2)
.Interior.Color = vbYellow
.Font.Color = vbRed
Case Is >= tTimes(i, 1)
.Interior.Color = vbGreen
.Font.Color = vbRed
Case Else
.Interior.Color = xlNone
.Font.Color = vbBlack
End Select
ElseIf bLowest = True Then
Select Case CDbl(.text)
Case Is = tTimes(i, 2)
.Interior.Color = vbYellow
.Font.Color = vbRed
Case Is <= tTimes(i, 1)
.Interior.Color = vbGreen
.Font.Color = vbRed
Case Else
.Interior.Color = xlNone
.Font.Color = vbBlack
End Select
End If
End With
End If
Next c
Next i
End Sub
 
S

Sam Harman

It should be fairly simple to do that. I would just write a sub that allows you to select all your columns, then that sub would sequentially call the second sub, which would be changed slightly to use the arguments provided by the first, rather than the InputBox, for the source data.

Are there multiple columns of date/times and a single column of numbers? Or are there multiple pairs of date/time - Numbers to be selected?

Hi Ron and thanks for the prompt reply....

I have uploaded a file to sky drive which I hope you can get a chance
to look at and hopefully it will explain better what I am hoping to
achieve.

https://skydrive.live.com/view.aspx?cid=CB2CB4829572A60A&resid=CB2CB4829572A60A!290

Thanks again


Kind regards

Sam
 
S

Sam Harman

For formatted cells it is fairly straightforward. See http://www.cpearson.com/excel/colors.aspx for a discussion.

For conditionally formatted cells, you need to test whether the format condition applies to the cell. So an algorithm might look like:

1. Is the cell conditionally formatted; if not --> Exit
2. Obtain the conditional format functions from the CF Object.
3. Test to see if any of the conditions apply, and count 1 if they do.

Thanks again Ron, I have tried all of the methods on the net,
including chip pearson, ozgrid, choobah, xlsdynamic atc but cannot
seem to get any of them to work properly.....really frustrating...

I just wondered if there was a simple macro that would do the trick?

Cheers

Sam
 
S

Stan Brown

Maybe you could use subject lines that actually describe your
problem. Ron's not the only one here who might help.

If you actually want to communicate with one person and only that
person, there's email, you know.
 
S

Sam Harman

Maybe you could use subject lines that actually describe your
problem. Ron's not the only one here who might help.

If you actually want to communicate with one person and only that
person, there's email, you know.

Sorry Stan but I have been posting with proper thread titles and Ron
has been very helpful in his responses.

My ISP does not keep headers for long and that is why I titled my
recent post FAO ROn so that it would hopefully attract his attention
as I am sure he doesnt read every thread on this newgroup.

It is not an exclusive invite for Ron only to help so feel free to
contribute....but as it was tweaks to already provided modules I
thought it best that I ask Ron direct.

Also I am not sure of the merits of postin an e-mail on here that is
why I have not conversed via email.

Regards

Sam
 
S

Sam Harman

Sorry Stan but I have been posting with proper thread titles and Ron
has been very helpful in his responses.

My ISP does not keep headers for long and that is why I titled my
recent post FAO ROn so that it would hopefully attract his attention
as I am sure he doesnt read every thread on this newgroup.

It is not an exclusive invite for Ron only to help so feel free to
contribute....but as it was tweaks to already provided modules I
thought it best that I ask Ron direct.

Also I am not sure of the merits of postin an e-mail on here that is
why I have not conversed via email.

Regards

Sam


Following on from that last post I have updated my spreadsheet to try
and explain better what I am trying to do.

Ron I tried your formula but could not get it to work and that is
probably largely because I did not explain myself properly - apologies
for that..

https://skydrive.live.com/view.aspx?cid=CB2CB4829572A60A&resid=CB2CB4829572A60A!292

Stan if you can add anything to themix it would be much appreciated.

Thanks as always Ron

Cheers

Sam
 
S

Sam Harman

Hi Ron, I am really sorry if I have not explained myself properly.

You have no idea how much you have helped me since I started
developing my spreadsheet and how much time your modules have saved
me.

I think you know how grateful I am and I am amazed at your knowledge,
patience and willingness to help when I manage to frustrate you with
poor examples or lack of clarity in what I am trying to achieve...

I will try this module and let you know how I get on...

Thank you once again for all your help

Kind regards

Sam
 

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

Top