Macro to append

T

Therm

OK folks, I know this isn't rocket science, but I cannot figure it
out. I have a column of cells and I simply want to append something
to the end of each cell, go down to the next cell, and append the same
thing. It can keep going until I hit the ESC key to keep things
simple or it can stop when the next cell is empty if I can get that
programmed as well. What currently happens is that the cell is
appended and then when it runs again, it simply copies everything from
the previous cell rather than append the few words I need.

Any help or suggestions are appreciated.

Therm
 
T

Therm

OK folks, I know this isn't rocket science, but I cannot figure it
out.  I have a column of cells and I simply want to append something
to the end of each cell, go down to the next cell, and append the same
thing.  It can keep going until I hit the ESC key to keep things
simple or it can stop when the next cell is empty if I can get that
programmed as well. What currently happens is that the cell is
appended and then when it runs again, it simply copies everything from
the previous cell rather than append the few words I need.

Any help or suggestions are appreciated.

Therm

OK, I got it to append using the following:
Sub addHello()
whatsthere = ActiveCell.Text
ActiveCell.Clear
ActiveCell.Value = whatsthere + " - Hello"

End Sub

So, can someone tell me how to move down a cell and repeat the process
automatically? Thanks.
 
D

Don Guillett

sub appendtoeach()' change for your column
lr =cells(rows.count,"A").end(xlup).row 'assumes header row
for each c in range("a2:a"&lr")
c.value= c.value and "-Hello"
next c
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
OK folks, I know this isn't rocket science, but I cannot figure it
out. I have a column of cells and I simply want to append something
to the end of each cell, go down to the next cell, and append the same
thing. It can keep going until I hit the ESC key to keep things
simple or it can stop when the next cell is empty if I can get that
programmed as well. What currently happens is that the cell is
appended and then when it runs again, it simply copies everything from
the previous cell rather than append the few words I need.

Any help or suggestions are appreciated.

Therm

OK, I got it to append using the following:
Sub addHello()
whatsthere = ActiveCell.Text
ActiveCell.Clear
ActiveCell.Value = whatsthere + " - Hello"

End Sub

So, can someone tell me how to move down a cell and repeat the process
automatically? Thanks.
 
D

Dave Peterson

Typo alert.

Sub appendtoeach()

Dim lr As Long
Dim c As Range
' change for your column

lr = Cells(Rows.Count, "A").End(xlUp).Row 'assumes header row
For Each c In Range("a2:a" & lr).Cells
c.Value = c.Value & "-Hello"
Next c
End Sub

(extra double quote after lr and "AND" instead of "&")

(And I declared a couple of variables, too.)
 

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