VBA code for cells in row

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Good Day All,

I'm trying to work on a code, where if a row has data in Columns B:E & G, and any information contained from that rows Column H:Z that when Column F is blank under these conditions that its interior cell color will turn red.

Likewise, if under this conditions Column F is not blank, the code will do nothing.

Please note, that this proposed criterion ignores Column A's information.

Can someone help me sort out a VBA for this?

Thank you in advance!

Respectfully,
pinaceous




Capture.PNG
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You can use a conditional format like this:

Dante Amor
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567891011121314151617181920212223242526
224471038453426119214273542319334713483236341515
3203217234632429345141337464946342721413422
4233849353237302928504529141818321632346842443
512362848454251682637491230692749393227302927
6284650123525636454885381848233949424324444
7241196
89374833203830191822172435443831382936364011454326
92850452923
Hoja3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:F9Expression=AND(COUNTA($B2:$E2,$G2:$Z2)=24,$F2="")textNO
 
Upvote 0
Hi DanteAmor,

How do I do that? Can you kindly break it down for me? I'm lost.

Is this under the 'New Formatting Rule'?

Thank you!
pinaceous
 
Upvote 0
Can you kindly break it down for me?
Of course:

1. Select the cells you want to format, for example Select cells F2 through F100.
2. On the Home tab, click Conditional Formatting > New Rule.
3. Select Use a formula to determine which cells to format.
1670934569495.png


4. In the next box, type the formula:
Excel Formula:
=AND(COUNTA($B2:$E2,$G2:$Z2)=24,$F2="")

5. Click custom format.
1670935874428.png


6. In the Format Cells dialog box, click the Fill tab.
7. Select Red color.
8. Click OK until the dialog boxes are closed.
 
Upvote 0
Hi DanteAmor,

I really appreciate that you helped me with the conditional formatting!

Okay, so now I believe that your formula needs to be adjusted because when your code applies to the sheet it looks like this:

Untitled.png


But I would like it to do this:

Untitled-2.png


According to:

"I'm trying to work on a code, where if a row has data in Columns B:E & G, and any information contained from that rows Column H:Z that when Column F is blank under these conditions that its interior cell color will turn red.

Likewise, if under this conditions Column F is not blank, the code will do nothing."


Can you please adjust your formula? And again, I really do appreciate that you coached me through the CF.

Respectfully,
pinaceous
 
Upvote 0
In my example I always referenced the cells starting at row 2.
In your data you have row 2 and row 1.
Change the 2 in the formula to the number 1:

1670983811409.png
 

Attachments

  • 1670983440514.png
    1670983440514.png
    49 KB · Views: 6
Last edited:
Upvote 0
One way:
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567891011121314151617181920212223242526
224471038453426119214273542319334713483236341515
3203217234632429345141337464946342721413422
4233849353237302928504529141818321632346842443
512362848454251682637491230692749393227302927
6284650123525636454885381848233949424324444
7241196
89374833203830191822172435443831382936364011454326
92850452923
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F1:F9Expression=AND(COUNT(B1:E1)=4,COUNT(G1:Z1)>0,F1="")textNO
 
Upvote 0
And, here is VBA code:
VBA Code:
Option Explicit
Sub color()
Dim lr&, cell As Range, rng As Range
Set rng = Range("F1:F" & Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlCellTypeBlanks)
For Each cell In rng
    cell.Interior.color = xlNone
    With WorksheetFunction
        If .Count(cell.Offset(, -4).Resize(1, 4)) = 4 And .Count(cell.Resize(, 21)) > 0 Then
            cell.Interior.color = vbRed
        End If
    End With
Next
End Sub
 
Upvote 0
Can you please adjust your formula? And again, I really do appreciate that you coached me through the CF.
Try this formula:
Excel Formula:
=AND(COUNTA($B1:$E1,$G1:$Z1)=24,$F1="")
 
Upvote 0
Okay thanks guys! I'll have to play around with it to see which one is best! Appreciate all of your efforts!
 
Upvote 0

Forum statistics

Threads
1,215,584
Messages
6,125,677
Members
449,248
Latest member
wayneho98

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