Vba code that fill all row cells with special color thats cells value is "Yes"

FaizanRoshan

Board Regular
Joined
Jun 11, 2015
Messages
54
Hi,
I use this code for fill row cells with color thats value is "Yes" based on another cell color.
Actually this code only fill one row at one time with special color.
i want code that will fill out all row cell that value is "yes" base on special color for each row.
Like: code fill row cell Range(m2:ac2) with color based on color cell "G2"
so if code fill row Range(m4:ac4) its color must be form cell "G4" and so on.
Is this possible using vba.
Here is code:

Sub Graph()
1 Column = Range("m" & Columns.Count).End(xlToRight).Column

Set MR = Range("M2:AC10000" & Row)
For Each cell In MR
If cell.Value = "Yes" Then cell.Interior.ColorIndex = Range("G2").Interior.ColorIndex


Next
End Sub

I have no experience wrting <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>.


Thanks in advance for your help!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,
Not sure what your first line is trying to achieve, but the following should work :

<code>
Set MR = Range("M2:AC10000")
For Each cell In MR
If cell.Value = "Yes" Then cell.Interior.ColorIndex = Range("G2").Interior.ColorIndex
Next
</code>

hth
 
Upvote 0
Thanks for the code, i just want when code fill row m4:ac4 or so on then its will be take color cell form "G4" Not on "G2". In each row code will take new color from that row.

my-drive
 
Upvote 0
Actually when i use this code its fill all row with same color based on "G2" cell color. I need to fill each row with its own special color form its row.
Is it possible using vba.

thanks
 
Upvote 0
Try:

<code>
Set MR = Range("M2:AC10000")
For Each cell In MR
If cell.Value = "Yes" Then cell.Interior.ColorIndex = Range("G"& cell.Row).Interior.ColorIndex
Next
</code>
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top