Thread: Case Select
View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mailto.jos@gmail.com is offline
external usenet poster
 
Posts: 6
Default Case Select

I couldn't obtain the right results with a case select, so i did it
with a For ... Next loop:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range

If Not IsEmpty(Target) Then
With Target
For Each cell In [Formats]
If Evaluate(.Value & cell) = True Then
cell.Offset(0, 1).Copy
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End If
Next cell
End With
End If
End Sub

I have a named range, "Formats", which is A1:A3, holding the text
"<50","=50","50".
Using the Evaluate function, I effectively test
If ("49<50"=TRUE) Then ...

The loop checks all the criteria in A1:A3, and if it finds a match, it
copies the format from the cell next to the criterium to the target
cell. In the example of the target cell holding '53', it would copy
the format of cell B3 (since the text "50" is in A3) to the active
cell.

Let me know if you get this to work/if it helped.