# Test to see if cell equals text

#### dwg83

##### Board Regular
I am trying to see if a cell has a certain word in it. What do I need to change in the following code:

Code:
``````    If ISheet.Cells(i, 2) = "Electricity" Then
FProduct.Cells(i - 1, 2) = "Electric" & emeters
FProduct.Cells(i - 1, 4) = "e"
FProduct.Cells(i - 1, 5) = 3413
FProduct.Cells(i - 1, 6) = 3413
eflag = True
ElseIf ISheet.Cells(i, 2) = "Natural Gas" Then
FProduct.Cells(i - 1, 2) = "Nat Gas" & gmeters
FProduct.Cells(i - 1, 4) = "g"
FProduct.Cells(i - 1, 5) = 100000
FProduct.Cells(i - 1, 6) = 100000
gflag = True
Else
End If``````

Thanks

Last edited:

### Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

#### VoG

##### Legend
Possibly

Code:
``````If ISheet.Cells(i, 2) Like "*Electricity*" Then
FProduct.Cells(i - 1, 2) = "Electric" & emeters
FProduct.Cells(i - 1, 4) = "e"
FProduct.Cells(i - 1, 5) = 3413
FProduct.Cells(i - 1, 6) = 3413
eflag = True
ElseIf ISheet.Cells(i, 2) Like "*Natural Gas*" Then
FProduct.Cells(i - 1, 2) = "Nat Gas" & gmeters
FProduct.Cells(i - 1, 4) = "g"
FProduct.Cells(i - 1, 5) = 100000
FProduct.Cells(i - 1, 6) = 100000
gflag = True
End If``````

#### dwg83

##### Board Regular
That worked. Is that typical when testing to see if a cell's value matches a text string...or is the Like a way to get around small differences?

#### VoG

##### Legend
Using Like "*word*" is equivalent to looking for word anywhere in the cell.

Replies
3
Views
104
Replies
6
Views
137
Replies
4
Views
100
Replies
11
Views
241
Replies
1
Views
95

1,190,800
Messages
5,982,984
Members
439,810
Latest member
phobo3s

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