View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default Delete Part of Cell?

Hi
try something like

sub foo()
dim rng as range
dim cell as range
Dim res
set rng=selection
for each cell in rng
res=application.trim(cell.value)
if right(res,1)="N") or right(res,1)="Y" then
cell.value=left(res,len(res)-1)
end if
next
end sub



"Odysseus" wrote:


Hi, I've been landed with a rather large project to re-write some
spreadsheets for my companies reports due to a new database... oh the
joys. I have no VBA experience and some basic macro usage. I've got 28
days to re-write about 10 worksheets so I may be popping in from time
to time to ask for some help.

My first question for today.

Can you delete part off a cell using a macro / VBA.

Example Cell from column (cost centre) :-

NTL089 N

I need to get rid of the N at the end, this could also be a Y. (yes or
no) This is used by certain departments for audit purposes so I can't
take it out of the DB export. Extra problems are that some may have
neither and some of the cost centres end in a Y or a N.

So the Macro needs to do a

If M column cells have a N or Y to the right preceded by 2 or more
spaces delete Y or N if not leave.

Does that make sense? Is it possible?

Thanks


--
Odysseus
------------------------------------------------------------------------
Odysseus's Profile: http://www.excelforum.com/member.php...o&userid=14563
View this thread: http://www.excelforum.com/showthread...hreadid=274129