if then

isacp

Board Regular
Joined
Dec 16, 2004
Messages
135
if cell contains xx then
can you help me with the wording of this code?
 
isacp,

It seems to me that it will be better for you to take a deep breath (perhaps go for a little walk) and then concentrate.

You seem to like the "Left" option
example : If Left(Range("A1"), 2) = "O.D."
then your code ...
don't use "item" since it is a "reserved term" in VBA
(you see that because it's getting un uppercase automatically)
let's use "cell" instead
I've inserted a messagebox so you can see what happens

open a new workbook
put in some testdata
paul steven jack Sting
select those data
run this macro
Code:
For Each cell In Selection
MsgBox Left(cell, 2)
If Left(cell, 2) = "st" Then cell.Offset(0, 5) = "st"
Next cell
you see?

regards,
Erik
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
thnak you eric
very much
now normally when i use a for each i use item in selection
what would be the difference if i use item or cell?
againn thanx for ur patients
 
Upvote 0
You're welcome!

About "Item" (or "Name", "Time", ...)
click in that word within your code and press F1
the Help will appear on that item :)
sometimes this specific word is needed by VBA itself, that's why we don't use it

test this:
type: name = "excel"
pressing ENTER it will change in Name = "excel"

you can do the same with item, ...

you see ?

regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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