ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to add data (https://www.excelbanter.com/excel-programming/302578-macro-add-data.html)

Janna[_3_]

Macro to add data
 
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

Norman Jones

Macro to add data
 
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



"Janna" wrote in message
...
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




Janna[_3_]

Macro to add data
 
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



"Janna" wrote in

message
...
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



.



All times are GMT +1. The time now is 03:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com