# Tricky Blanks

#### StefanRSA

##### New Member
Hi Guys,

Im trying to go through a list of names, find the blank one, then add a name into it. I tried using a FOR loop but it keeps adding for every blank all the way down the list, not just the first one.

Any advice on how to exit the FOR loop when the IF statement is TRUE? Or perhaps a different method to achieve the same end?

For x = 10 To 209
If Cells(x, 2) = "" Then
Cells(x, 2).Value = Employee
End If
Next

Stefan

### Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

#### DonkeyOte

##### MrExcel MVP
after

cells(x,2).value = Employee

Exit Sub (or Exit For if you want to do actions outside the loop)

alternative you can find the first blank and adjust that... horses for courses

#### Jonmo1

##### MrExcel MVP
to Exit a Loop use Exit For

For x = 10 To 209
If Cells(x, 2) = "" Then
Cells(x, 2).Value = Employee
Exit For
End If
Next

But, the same thing can be done without a loop...

Try this, it simulates pressing CTRL + DOWN to find the last cell before the first blank, then goes down 1 cell (to the first blank)...

Cells(10,2).End(xldown).Offset(1,0).Value = Employee

Hope that helps...

#### schielrn

##### Well-known Member
If you only want the first one try this:

Code:
``````For x = 10 To 209
If Cells(x, 2) = "" Then
Cells(x, 2).Value = Employee
Exit For
End If
Next``````
You can also use exit sub to exit the procedure. Hope that helps.

#### facethegod

##### Well-known Member

Try.......

Code:
``````Sub tst()

Cells(9, 2).End(xlDown).Offset(1, 0) = "Employee"

End Sub``````

HTH

#### StefanRSA

##### New Member
Hi Guys,

Thanks for so many responses!

PROBLEM SOLVED

Thank you again...

#### Jonmo1

##### MrExcel MVP
By Using (9,2), FaceTheGood made me think about why use 9, when the OP started with row 10...

My 1 line solution
Cells(10,2).End(xldown).Offset(1,0).Value = Employee
will give odd results if the first blank happens to be in row 10 or 11...

FaceTheGood tried to accomodate for that by starting at row 9, But it would have the same problem if the first blank row happened to be 10.

so that got me thinking...
This will work better...

Cells(10, 2).Resize(200).SpecialCells(xlCellTypeBlanks)(1).Value = Employee

However, it's not flawless either, it will fail if there are NO blanks in the range...

So need a few lines, but still not a loop...

Dim MyRange As Range
On Error Resume Next
Set MyRange = Cells(10, 2).Resize(200).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not MyRange Is Nothing Then MyRange(1).Value = Employee

Last edited:

#### RoryA

##### MrExcel MVP, Moderator
Just a thought:
Code:
``columns(2).find(what:="", after:=cells(9,2), searchdirection:=xlnext).value = Employee``
but: assumes the column is not full!

Replies
1
Views
63
Replies
13
Views
423
Replies
10
Views
210
Replies
0
Views
130
Replies
24
Views
2K

1,130,118
Messages
5,640,216
Members
417,131
Latest member
Seanr19871

### 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.

### Which adblocker are you using?

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

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