Need help Finishing code.

Lynxador

Board Regular
Joined
Jan 6, 2005
Messages
125
i need to find out how to finish this code. but im having trouble with just 2 parts of it. the Do until Statement, and the function to Fill a cell with the color red.

Code:
x = 4

Do until (end of sheet)
      If Cells(x, 1) = "" Than
      Cells(x, 1) (fill in box red)
x = x + 9
Loop

any help would be greatly appreciated.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,315
Office Version
  1. 365
Platform
  1. Windows
If you just want it to down to the last row with data, try:
Code:
    Dim x As Long
    Dim myLastRow As Long
    
'   Find last row of column A
    myLastRow = Cells(65536, 1).End(xlUp).Row

    x = 4

    Do Until x > myLastRow
        If Cells(x, 1) = "" Then Cells(x, 1).Interior.ColorIndex = 3
        x = x + 9
    Loop
If you want to do all rows, then change myLastRow to 65536 (no formula).
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hello Lynxador,
Along with jm14's, example, here are a couple more that work too.
Code:
Dim x As Long, LstRw As Long
x = 4
LstRw = Cells(Rows.Count, 1).End(xlUp).Row
While x < LstRw
  If Cells(x, 1) = "" Then Cells(x, 1).Interior.ColorIndex = 3 '(fill in box red)
  x = x + 9
Wend

And . . .
Code:
Dim x As Long, LstRw As Long
LstRw = Cells(Rows.Count, 1).End(xlUp).Row
For x = 4 To LstRw Step 9
  If Cells(x, 1) = "" Then Cells(x, 1).Interior.ColorIndex = 3 '(fill in box red)
Next x

And lastly, if these cells are the only blank cells in column A (used range) then you can
do it without looping at all.
Code:
Dim LstRw As Long
LstRw = Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(4, 1), Cells(LstRw, 1)).SpecialCells(xlCellTypeBlanks).Interior.ColorIndex = 3
 

Forum statistics

Threads
1,136,655
Messages
5,677,017
Members
419,668
Latest member
DharmaK

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
Top