Macro to add data

  • Thread starter Thread starter Janna
  • Start date Start date
J

Janna

I have a column in a table to which I would like to add
the same data to every record in the column. Following
is an example: Each record in my column B of the
spreadsheet contains a unique value. I would like to
preface that unique value, in every record in column B
with the same path name. So if B2 currently
contains "1233" in the field. I would like the macro to
add "c:\data\" in front of it so the final result of the
field is "c:\data\1233


TIA
 
Hi Janna,

Assuming that your table has a header row, try:

Sub Tester()
Dim rng As Range, cell As Range
Dim Lstcell As Range

Set Lstcell = Cells(Rows.Count, "B").End(xlUp)

Set rng = Range(Lstcell, Lstcell.End(xlUp)(2))

For Each cell In rng
cell.Value = "c:\data\" & cell.Value
Next

End Sub
 
Thanks Norman

It worked like a charm :-)

Janna
-----Original Message-----
Hi Janna,

Assuming that your table has a header row, try:

Sub Tester()
Dim rng As Range, cell As Range
Dim Lstcell As Range

Set Lstcell = Cells(Rows.Count, "B").End(xlUp)

Set rng = Range(Lstcell, Lstcell.End(xlUp)(2))

For Each cell In rng
cell.Value = "c:\data\" & cell.Value
Next

End Sub


---
Regards,
Norman






.
 

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

Back
Top