Test to see if cell equals text

dwg83

Board Regular
Joined
Nov 8, 2006
Messages
174
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
 
Upvote 0
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?

Regardless, thanks for the answer
 
Upvote 0
Using Like "*word*" is equivalent to looking for word anywhere in the cell.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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