Macro to add data

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
 
N

Norman Jones

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
 
J

Janna

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






.
 
Top