ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VBA - Coloring Rows Instead of Cells (https://www.excelbanter.com/excel-discussion-misc-queries/141638-vba-coloring-rows-instead-cells.html)

J-D

VBA - Coloring Rows Instead of Cells
 
Please Help!

I'm using the following in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

It change the color in that cell but I want it to color the row from coulums
A to N? Can somebody show me how to do that?


Dom_Ciccone

VBA - Coloring Rows Instead of Cells
 
Simply add a loop using the targets row property:


For myloop = 1 To 14
ActiveSheet.Cells(Target.Row, myloop).Interior.ColorIndex = icolor
Next




"J-D" wrote:

Please Help!

I'm using the following in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

It change the color in that cell but I want it to color the row from coulums
A to N? Can somebody show me how to do that?


PCLIVE

VBA - Coloring Rows Instead of Cells
 
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Stop
Target.EntireRow.Interior.ColorIndex = icolor
End If

End Sub


"J-D" wrote in message
...
Please Help!

I'm using the following in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

It change the color in that cell but I want it to color the row from
coulums
A to N? Can somebody show me how to do that?




J-D[_2_]

VBA - Coloring Rows Instead of Cells
 
Excellent! Thank you Dom_Ciccone.

"Dom_Ciccone" wrote:

Simply add a loop using the targets row property:


For myloop = 1 To 14
ActiveSheet.Cells(Target.Row, myloop).Interior.ColorIndex = icolor
Next




"J-D" wrote:

Please Help!

I'm using the following in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

It change the color in that cell but I want it to color the row from coulums
A to N? Can somebody show me how to do that?


PCLIVE

VBA - Coloring Rows Instead of Cells
 
Oops! "Stop" should not have been left in the code.

"PCLIVE" wrote in message
...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Stop
Target.EntireRow.Interior.ColorIndex = icolor
End If

End Sub


"J-D" wrote in message
...
Please Help!

I'm using the following in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

It change the color in that cell but I want it to color the row from
coulums
A to N? Can somebody show me how to do that?







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

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