PC Review


Reply
Thread Tools Rate Thread

Amend sheet sub to work if input range contains formulas

 
 
Max
Guest
Posts: n/a
 
      15th Jan 2008
The sheet sub below works fine if I input the values (1-6) manually into
V2:V250. How can it be amended to work if V2:V250 contains formulas
returning the values 1-6 instead? Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("V2:V250")) Is Nothing Then
Select Case Target
Case 1
icolor = 10
fcolor = 2
Case 2
icolor = 50
fcolor = 2
Case 3
icolor = 4
fcolor = 1
Case 4
icolor = 35
fcolor = 1
Case 5
icolor = 44
fcolor = 1
Case 6
icolor = 45
fcolor = 2
Case Else
End Select
With Target
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
End If
End Sub


 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      15th Jan 2008
Max,

Try this, it's got a bit messy but it works:-

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
Set myrange = Range("V2:V250")
For Each c In myrange
Select Case c.Value
Case 1
icolor = 10
fcolor = 2
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case 2
icolor = 50
fcolor = 2
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case 3
icolor = 4
fcolor = 1
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case 4
icolor = 35
fcolor = 1
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case 5
icolor = 44
fcolor = 1
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case 6
icolor = 45
fcolor = 2
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
End With
Case Else
With c
.Offset(0, -21).Resize(1, 21).Interior.ColorIndex = xlNone
.Offset(0, -21).Resize(1, 21).Font.ColorIndex = 0
End With
End Select
Next
End Sub

Mike


"Max" wrote:

> The sheet sub below works fine if I input the values (1-6) manually into
> V2:V250. How can it be amended to work if V2:V250 contains formulas
> returning the values 1-6 instead? Thanks
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim icolor As Integer
> If Not Intersect(Target, Range("V2:V250")) Is Nothing Then
> Select Case Target
> Case 1
> icolor = 10
> fcolor = 2
> Case 2
> icolor = 50
> fcolor = 2
> Case 3
> icolor = 4
> fcolor = 1
> Case 4
> icolor = 35
> fcolor = 1
> Case 5
> icolor = 44
> fcolor = 1
> Case 6
> icolor = 45
> fcolor = 2
> Case Else
> End Select
> With Target
> .Offset(0, -21).Resize(1, 21).Interior.ColorIndex = icolor
> .Offset(0, -21).Resize(1, 21).Font.ColorIndex = fcolor
> End With
> End If
> End Sub
>
>
>

 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      15th Jan 2008
Many thanks, Mike. It works fine.


 
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
how to copy formulas from one range to another range in other work =?Utf-8?B?TWlyaQ==?= Microsoft Excel Programming 1 6th Jun 2007 03:52 PM
Input formulas in a defined data range and convert results as valu =?Utf-8?B?VGFu?= Microsoft Excel New Users 0 18th Apr 2007 12:54 AM
sheet protection - only selected range to be able to select/input data Corey Microsoft Excel Worksheet Functions 7 13th Feb 2007 05:41 PM
input conditional formulas using VBA Macro in axcel sheet =?Utf-8?B?RnJhbmNlc2Nv?= Microsoft Excel Misc 7 2nd Apr 2006 01:51 PM
Input box doesn't return sheet name with range =?Utf-8?B?cXVhcnR6?= Microsoft Excel Programming 1 24th Aug 2004 04:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 AM.