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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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).
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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