ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying a Value Down a Column for Every Value in An Adjacent Colum (https://www.excelbanter.com/excel-programming/331708-copying-value-down-column-every-value-adjacent-colum.html)

Charles Allen[_3_]

Copying a Value Down a Column for Every Value in An Adjacent Colum
 
I am trying to write a macro that does three things.

1. Inserts a column in front of a column.
2. Enters a value in the first row of the new empty column that is next to
the first cell in the old column.
3. Copy the contents of the cell to every cell adjacent to the next column.

So, imagine that Column A contains three rows of data:
Football
Basketball
Baseball

I want to insert a column in front of Column A. I then want to insert the
value "2005" for every row based on how many rows are in column B.

Thank you.

Liedson31

Copying a Value Down a Column for Every Value in An Adjacent Colum
 
hi Charles.
Try something like this:

Dim LastRow
Range("A1").Select
Selection.End(xlDown).Select
LastRow = ActiveCell.Row

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
cells(1,1) = "2005"
Selection.AutoFill Destination:=Range(cells(1,1),cells(LastRow,1)),
Type:=xlFillDefault

Miguel

"Charles Allen" wrote:

I am trying to write a macro that does three things.

1. Inserts a column in front of a column.
2. Enters a value in the first row of the new empty column that is next to
the first cell in the old column.
3. Copy the contents of the cell to every cell adjacent to the next column.

So, imagine that Column A contains three rows of data:
Football
Basketball
Baseball

I want to insert a column in front of Column A. I then want to insert the
value "2005" for every row based on how many rows are in column B.

Thank you.


Liedson31

Copying a Value Down a Column for Every Value in An Adjacent C
 
hi again i forgot 1 thing:
Dim LastRow
Range("A1").Select
Selection.End(xlDown).Select
LastRow = ActiveCell.Row

Columns("A:A").Select
Selection.Insert Shift:=xlToRight

cells(1,1).select
cells(1,1) = "2005"
Selection.AutoFill Destination:=Range(cells(1,1),cells(LastRow,1)),
Type:=xlFillDefault


"Liedson31" wrote:

hi Charles.
Try something like this:

Dim LastRow
Range("A1").Select
Selection.End(xlDown).Select
LastRow = ActiveCell.Row

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
cells(1,1) = "2005"
Selection.AutoFill Destination:=Range(cells(1,1),cells(LastRow,1)),
Type:=xlFillDefault

Miguel

"Charles Allen" wrote:

I am trying to write a macro that does three things.

1. Inserts a column in front of a column.
2. Enters a value in the first row of the new empty column that is next to
the first cell in the old column.
3. Copy the contents of the cell to every cell adjacent to the next column.

So, imagine that Column A contains three rows of data:
Football
Basketball
Baseball

I want to insert a column in front of Column A. I then want to insert the
value "2005" for every row based on how many rows are in column B.

Thank you.


Charles Allen[_3_]

Copying a Value Down a Column for Every Value in An Adjacent Colum
 
Thank you very much. Your assistance has proven very valuable.

"Charles Allen" wrote:

I am trying to write a macro that does three things.

1. Inserts a column in front of a column.
2. Enters a value in the first row of the new empty column that is next to
the first cell in the old column.
3. Copy the contents of the cell to every cell adjacent to the next column.

So, imagine that Column A contains three rows of data:
Football
Basketball
Baseball

I want to insert a column in front of Column A. I then want to insert the
value "2005" for every row based on how many rows are in column B.

Thank you.



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

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