ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to paste data to a new column if previous column has data (https://www.excelbanter.com/excel-programming/383071-macro-paste-data-new-column-if-previous-column-has-data.html)

Neil[_29_]

Macro to paste data to a new column if previous column has data
 
Hello,

I have a range of data in column A. I want to be able to run a macro
and paste it into another column (C). Then later when i make a change
to the data in column A, i want to be able to paste it into the next
available column (in this particular example it would be column D).

Any help would be much appreciated.

Thanks
Neil


John Green

Macro to paste data to a new column if previous column has data
 
Hi Neil,

Assuming that your data to be copied starts in row 1, you could use
something like the following:

Sub CopyToNextEmptyColumn()
Dim rngSource As Range
Dim rngDestination As Range

Set rngSource = Range("A1:A12")
Set rngDestination = Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)

rngSource.Copy Destination:=rngDestination
End Sub

If there is an entry in B1 and nothing in the cells to the left of B1, the
above code will make the first copy in the C column and subsequent copies in
the next empty column.

John Green

"Neil" wrote in message
ups.com...
Hello,

I have a range of data in column A. I want to be able to run a macro
and paste it into another column (C). Then later when i make a change
to the data in column A, i want to be able to paste it into the next
available column (in this particular example it would be column D).

Any help would be much appreciated.

Thanks
Neil




Neil[_29_]

Macro to paste data to a new column if previous column has data
 
On Feb 13, 2:03 pm, "John Green" <greenj@nospam wrote:
Hi Neil,

Assuming that your data to be copied starts in row 1, you could use
something like the following:

Sub CopyToNextEmptyColumn()
Dim rngSource As Range
Dim rngDestination As Range

Set rngSource = Range("A1:A12")
Set rngDestination = Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)

rngSource.Copy Destination:=rngDestination
End Sub

If there is an entry in B1 and nothing in the cells to the left of B1, the
above code will make the first copy in the C column and subsequent copies in
the next empty column.

John Green

"Neil" wrote in message

ups.com...



Hello,


I have a range of data in column A. I want to be able to run a macro
and paste it into another column (C). Then later when i make a change
to the data in column A, i want to be able to paste it into the next
available column (in this particular example it would be column D).


Any help would be much appreciated.


Thanks
Neil- Hide quoted text -


- Show quoted text -


Thanks John - it works great.

Cheers
Neil


Neil[_29_]

Macro to paste data to a new column if previous column has data
 
On Feb 13, 4:02 pm, "Neil" wrote:
On Feb 13, 2:03 pm, "John Green" <greenj@nospam wrote:





Hi Neil,


Assuming that your data to be copied starts in row 1, you could use
something like the following:


Sub CopyToNextEmptyColumn()
Dim rngSource As Range
Dim rngDestination As Range


Set rngSource = Range("A1:A12")
Set rngDestination = Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)


rngSource.Copy Destination:=rngDestination
End Sub


If there is an entry in B1 and nothing in the cells to the left of B1, the
above code will make the first copy in the C column and subsequent copies in
the next empty column.


John Green


"Neil" wrote in message


oups.com...


Hello,


I have a range of data in column A. I want to be able to run a macro
and paste it into another column (C). Then later when i make a change
to the data in column A, i want to be able to paste it into the next
available column (in this particular example it would be column D).


Any help would be much appreciated.


Thanks
Neil- Hide quoted text -


- Show quoted text -


Thanks John - it works great.

Cheers
Neil- Hide quoted text -

- Show quoted text -


Hi John,

A further query.

Say i pasted data into columns C, D, E. i then find that i don't want
to keep the data in column D. How would i go about altering the above
code so that it finds the next available column as column D rather
than F.



All times are GMT +1. The time now is 12:42 PM.

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