Cell text manipulation

G

GR3G2K

My request should be fairly simple: I need to know where the content of a
cell (not format or anything else) is stored for being used in VBA. If I have
multiple cells selected, I want to know how to reference the content of each
one, and later apply some changes to each one in the selection.

Below is the practical application of what I'm trying to implement:

I'm creating a macro for some accountants and I need to get them to format
their tables correctly. If a cell contains a negative number, it appears in
brackets. The problem is, the comas from each cell won't align because
positive numbers don't use brackets, so the position of the comas on a colum
will vary.

All I want is a simple macro that, with multiple rows selected, after a
certain key combination, will add a blank space to the end of a positive
number and leave negative numbers untouched. I've been looking over it and
suppose it's down to using If clauses, so if the last char of the cell isn't
a ")", it will append a blank space (or empty char) to the end of the cell's
contents.

Thanks
 
J

Jean-Guy Marcil

GR3G2K was telling us:
GR3G2K nous racontait que :
My request should be fairly simple: I need to know where the content
of a cell (not format or anything else) is stored for being used in
VBA. If I have multiple cells selected, I want to know how to
reference the content of each one, and later apply some changes to
each one in the selection.

Below is the practical application of what I'm trying to implement:

I'm creating a macro for some accountants and I need to get them to
format their tables correctly. If a cell contains a negative number,
it appears in brackets. The problem is, the comas from each cell
won't align because positive numbers don't use brackets, so the
position of the comas on a colum will vary.

All I want is a simple macro that, with multiple rows selected, after
a certain key combination, will add a blank space to the end of a
positive number and leave negative numbers untouched. I've been
looking over it and suppose it's down to using If clauses, so if the
last char of the cell isn't a ")", it will append a blank space (or
empty char) to the end of the cell's contents.

You do not need a macro for this.
Just apply a style that contains a decimal tab to the cells where you want
the decimal separator aligned. That is what the decimal tab was designed
for.

Spot the tab icon on the leftmost side of the horizontal ruler (A right
angle). Click on it until it becomes an upside-down "T" with a dot on the
right side.
Select the cell where you want this tab. Click on the ruler to insert the
tab at the position you want. Make sure that the cell is left aligned. Test
it with different numbers. Slide the decimal tab on the ruler until it is
set at the position you want. Then select the text in the cell and create a
style based on the selection. Finally, apply this style to all cells where
you want this behaviour.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top