Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Change the Color of a Cell through a Macro

I am trying to change the color of a group of cells based upon the value of
a different cell. I have the macro below, but it does not seem to work - any
advice.

Thanks,




Sub changecolor()


If r8c1 = AR004328 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If r8c1 = AR004072 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Change the Color of a Cell through a Macro

Try this... or just use conditional formatting...

Sub changecolor()
If range("a8").value = "AR004328" Then
With Range("J10:J189").Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If range("a8").value = "AR004072" Then

With Range("J10:J189").Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub

--
HTH...

Jim Thomlinson


"JakeShipley2008" wrote:

I am trying to change the color of a group of cells based upon the value of
a different cell. I have the macro below, but it does not seem to work - any
advice.

Thanks,




Sub changecolor()


If r8c1 = AR004328 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If r8c1 = AR004072 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default Change the Color of a Cell through a Macro


Try moving one "End If" to just below the first "End With"
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"JakeShipley2008"

wrote in message
I am trying to change the color of a group of cells based upon the value of
a different cell. I have the macro below, but it does not seem to work - any
advice.
Thanks,

Sub changecolor()
If r8c1 = AR004328 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If r8c1 = AR004072 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Change the Color of a Cell through a Macro

hi
try it with a slight modification.
if all you are doing is changing the back color, you don't need the with
clause.
Sub changecolor()
If Cells(8, 1).Value = "AR004328" Then
Range("J10:J189").Interior.ColorIndex = 1
Else
If Cells(8, 1).Value = "AR004072" Then
Range("J10:J189").Interior.ColorIndex = 38
End If
End If
End Sub

regards
FSt1

"JakeShipley2008" wrote:

I am trying to change the color of a group of cells based upon the value of
a different cell. I have the macro below, but it does not seem to work - any
advice.

Thanks,




Sub changecolor()


If r8c1 = AR004328 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If r8c1 = AR004072 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Change the Color of a Cell through a Macro

Thanks everyone!! Works like a charm!!
--
Jake


"FSt1" wrote:

hi
try it with a slight modification.
if all you are doing is changing the back color, you don't need the with
clause.
Sub changecolor()
If Cells(8, 1).Value = "AR004328" Then
Range("J10:J189").Interior.ColorIndex = 1
Else
If Cells(8, 1).Value = "AR004072" Then
Range("J10:J189").Interior.ColorIndex = 38
End If
End If
End Sub

regards
FSt1

"JakeShipley2008" wrote:

I am trying to change the color of a group of cells based upon the value of
a different cell. I have the macro below, but it does not seem to work - any
advice.

Thanks,




Sub changecolor()


If r8c1 = AR004328 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

If r8c1 = AR004072 Then
Range("J10:J189").Select
With Selection.Interior
.ColorIndex = 38
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change a cell color based on its content using macro? Ranger888 New Users to Excel 6 December 15th 08 08:23 PM
Macro to change cell color Patti F Excel Discussion (Misc queries) 2 April 28th 06 07:13 PM
Macro To Change Cell Color (Continued) carl Excel Worksheet Functions 0 March 15th 06 03:10 PM
Macro To Change Cell Color When Value Changes carl Excel Worksheet Functions 4 March 14th 06 08:24 PM
Macro to change cell text color James C Excel Discussion (Misc queries) 1 August 12th 05 06:59 PM


All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"