# Ranges and Variables

#### StefanRSA

##### New Member
Hi Guys,

Must be getting annoyed with all my N00b questions...

Im trying to use a bit of code to clear a set range of cells. However, Im not sure of how the syntax should be. I have removed where the row references were and replaced them with a variable - y.

I have tried the following but no success:

For y = 10 To 209
If Cells(y, 2) = Employee Then
Range("B:AG").ClearContents
Exit For
End If
Next

Any ideas on the syntax?

### Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

#### Richard Schollar

##### MrExcel MVP
Hi Stefan

That would be:

Code:
``````For y = 10 To 209
If Cells(y, 2) = Employee Then
Range("B" & y & ":AG" &  y).ClearContents
Exit For
End If
Next``````

#### VoG

##### Legend
Try

Code:
``Range("B" & y & ":AG" & y).ClearContents``

#### xld

##### Banned
Code:
``````For y = 10 To 209
If Cells(y, 2) = Employee Then
Range(Cells(y,"B"),Cells(y,"AG")).ClearContents
Exit For
End If
Next``````

#### StefanRSA

##### New Member

Thanks again, sorry I have not studied VB6, am trying to teach myself as I go along.

I appreciate your help very much.

#### RoryA

##### MrExcel MVP, Moderator
or:
Code:
``cells(y,2).resize(,32).ClearContents``

#### Richard Schollar

##### MrExcel MVP
Having read further about what it was you were actually attempting to do, I think the following also achieves what you want but much more efficiently:

Code:
``````Dim r As Range
'...

With Range("B10:B209")
Set r = .Find(What:=Employee,After:=.Cells(.Rows.Count,1),SearchDirection:=xlNext)
If Not r Is Nothing Then Range(r,"AG"&r.Row).ClearContents
End With``````

#### StefanRSA

##### New Member
Ah, so it does... thanks Richard.

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,164,506
Messages
5,837,743
Members
430,515
Latest member
K_Lynch

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