Modify each cell in selection

C

Clayman

I need to modify each cell in a selection, adding a string constant to the
text in each cell. ie:
- a1="A"
- b1="B"
- c1="0"
- d1="E"

and I need to add "(DR1)" to each of these. I've tried researching "For
Each" 'cuz I know that is what I need, but I'm not certain exactly where to
go from there. My thoughts (reserved words may be ignored):

For Each cell In Selection
holder=cell.value
holder=holder & "(DR1)"
cell.value=holder
Next

Will this do it?
 
J

Jim Thomlinson

Your code should work but you could shorten it up a bit...

dim Cell as range

for each cell in Selection
cell.value = cell.value & "(DR)"
nect cell
 
J

Jim Thomlinson

Typo... nect should be next...

dim Cell as range

for each cell in Selection
cell.value = cell.value & "(DR)"
next cell
 
C

Clayman

Sanctuary much, Jim!
This worked quite well. I actually learned quite a bit during this little
endeavor - mostly how the "Range" type works. I had no idea it would be that
simple!
 

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