ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting values by row color (https://www.excelbanter.com/excel-programming/347085-setting-values-row-color.html)

Ron

Setting values by row color
 
Hi,

I need to set the values (Peoples names) of a column according to the fill
color of each row.

Can anyone please point me in the right direction with this problem.

I'm a VBA newbie by the way!


Regards,
Ron.

Bob Phillips[_6_]

Setting values by row color
 

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Interior.ColorIndex
Case 3: .Value = "Bill" 'red
Case 6: .Value = "John" 'yellow
Case 5: .Value = "Ron" 'blue
Case 10: .Value = "Alan" 'green
'etc.
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ron" wrote in message
...
Hi,

I need to set the values (Peoples names) of a column according to the fill
color of each row.

Can anyone please point me in the right direction with this problem.

I'm a VBA newbie by the way!


Regards,
Ron.




Ron

Setting values by row color
 
Thanks Bob,

That works fine I will have to iterate through the rows though because the
event type doesn't quite suit the way the sheet will be used.


Regards,
Ron.

"Bob Phillips" wrote:


Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Interior.ColorIndex
Case 3: .Value = "Bill" 'red
Case 6: .Value = "John" 'yellow
Case 5: .Value = "Ron" 'blue
Case 10: .Value = "Alan" 'green
'etc.
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ron" wrote in message
...
Hi,

I need to set the values (Peoples names) of a column according to the fill
color of each row.

Can anyone please point me in the right direction with this problem.

I'm a VBA newbie by the way!


Regards,
Ron.






All times are GMT +1. The time now is 07:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com