Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default loop to copy paste

Hi,

I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".

As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...

Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default loop to copy paste

On Nov 11, 2:24*pm, Norvascom wrote:
Hi,

I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".

As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...

Thanks for your help.

Send your file with a complete explanation and before/after examples
to dguillett1 * * *
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default loop to copy paste

On Nov 11, 4:09*pm, Don Guillett wrote:
On Nov 11, 2:24*pm, Norvascom wrote: Hi,

I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".


As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...


Thanks for your help.


Send your file with a complete explanation and before/after examples
to dguillett1 * * *


This assumes you do not know the start row or column of the source
sheet or the length of each column. Be sure to save your file as
an .xls or .xlsM file for macros.
'=============
Option Explicit
Sub CopyColumnsToOneColumnSAS()

Dim ss As Worksheet
Dim ds As Worksheet
Dim fr As Long 'find first row in souce sheet
Dim fc As Long 'find first column
Dim i As Long ' number of times to do it
Dim slr As Long 'find last row for each column
Dim dlr As Long 'find next available row in destination

Set ss = Sheets("sheet1")
Set ds = Sheets("sheet2")
Application.ScreenUpdating = False
ds.Columns(2).Clear
fr = ss.Cells.Find(What:="*").Row + 1 '7 row 7
fc = ss.Cells.Find(What:="*").Column '4 col D
For i = fc To ss.Cells(fr, Columns.Count).End(xlToLeft).Column
slr = ss.Cells(Rows.Count, i).End(xlUp).Row ;row 40
dlr = ds.Cells(Rows.Count, 2).End(xlUp).Row + 1
ss.Cells(fr, i).Resize(slr).Copy ds.Cells(dlr, 2)
Next i
Application.ScreenUpdating = True
End Sub







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default loop to copy paste

On Nov 13, 6:33*pm, Don Guillett wrote:
On Nov 11, 4:09*pm, Don Guillett wrote:





On Nov 11, 2:24*pm, Norvascom wrote: Hi,


I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".


As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...


Thanks for your help.


Send your file with a complete explanation and before/after examples
to dguillett1 * * *


This assumes you do not know the start row or column of the source
sheet or the length of each column. Be sure to save your file as
an .xls or .xlsM file for macros.
'=============
Option Explicit
Sub CopyColumnsToOneColumnSAS()

Dim ss As Worksheet
Dim ds As Worksheet
Dim fr As Long 'find first row in souce sheet
Dim fc As Long 'find first column
Dim i As Long ' number of times to do it
Dim slr As Long 'find last row for each column
Dim dlr As Long 'find next available row in destination

Set ss = Sheets("sheet1")
Set ds = Sheets("sheet2")
Application.ScreenUpdating = False
ds.Columns(2).Clear
fr = ss.Cells.Find(What:="*").Row + 1 * '7 row 7
fc = ss.Cells.Find(What:="*").Column * '4 col D
For i = fc To ss.Cells(fr, Columns.Count).End(xlToLeft).Column
slr = ss.Cells(Rows.Count, i).End(xlUp).Row * ;row 40
dlr = ds.Cells(Rows.Count, 2).End(xlUp).Row + 1
ss.Cells(fr, i).Resize(slr).Copy ds.Cells(dlr, 2)
Next i
Application.ScreenUpdating = True
End Sub- Hide quoted text -

- Show quoted text -


Thanks Don. It works perfectly.
However, what if I want to have it columns specifics (column D to S
only) and starts at a specific row (row 7 in my case).
Indeed, my report will then include titles and additional columns that
I don't want to have copied to "Sheet2".

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default loop to copy paste

On Nov 13, 8:05*pm, Norvascom wrote:
On Nov 13, 6:33*pm, Don Guillett wrote:









On Nov 11, 4:09*pm, Don Guillett wrote:


On Nov 11, 2:24*pm, Norvascom wrote: Hi,


I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".


As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...


Thanks for your help.


Send your file with a complete explanation and before/after examples
to dguillett1 * * *


This assumes you do not know the start row or column of the source
sheet or the length of each column. Be sure to save your file as
an .xls or .xlsM file for macros.
'=============
Option Explicit
Sub CopyColumnsToOneColumnSAS()


Dim ss As Worksheet
Dim ds As Worksheet
Dim fr As Long 'find first row in souce sheet
Dim fc As Long 'find first column
Dim i As Long ' number of times to do it
Dim slr As Long 'find last row for each column
Dim dlr As Long 'find next available row in destination


Set ss = Sheets("sheet1")
Set ds = Sheets("sheet2")
Application.ScreenUpdating = False
ds.Columns(2).Clear
fr = ss.Cells.Find(What:="*").Row + 1 * '7 row 7
fc = ss.Cells.Find(What:="*").Column * '4 col D
For i = fc To ss.Cells(fr, Columns.Count).End(xlToLeft).Column
slr = ss.Cells(Rows.Count, i).End(xlUp).Row * ;row 40
dlr = ds.Cells(Rows.Count, 2).End(xlUp).Row + 1
ss.Cells(fr, i).Resize(slr).Copy ds.Cells(dlr, 2)
Next i
Application.ScreenUpdating = True
End Sub- Hide quoted text -


- Show quoted text -


Thanks Don. It works perfectly.
However, what if I want to have it columns specifics (column D to S
only) and starts at a specific row (row 7 in my case).
Indeed, my report will then include titles and additional columns that
I don't want to have copied to "Sheet2".


I wrote it as if you did NOT know which to use so just change
fr = 7 'ss.Cells.Find(What:="*").Row + 1
fc = 4 'ss.Cells.Find(What:="*").Column
For i = fc To 19 ' ss.Cells(fr, Columns.Count).End(xlToLeft).Column


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default loop to copy paste

On Nov 14, 8:05*am, Don Guillett wrote:
On Nov 13, 8:05*pm, Norvascom wrote:





On Nov 13, 6:33*pm, Don Guillett wrote:


On Nov 11, 4:09*pm, Don Guillett wrote:


On Nov 11, 2:24*pm, Norvascom wrote: Hi,


I have two worksheets within the same workbook. On the first worksheet
"Sheet1" I have data on column D to S starting on row 7. The number of
row evolves over time. I am trying to create a loop to copy paste data
from "Sheet1" to "Sheet 2". However, on the destination "Sheet2", data
should be reported on only one column starting on cell B2. Each of the
data on the columns of "Sheet1" should go below each other on
"Sheet2".


As a example range D7:D40 in "Sheet1" should be copied on "Sheet2"
B2:B35. Then range E7:E40 in "Sheet1" should be copied on "Sheet2"
B36:B69, etc...


Thanks for your help.


Send your file with a complete explanation and before/after examples
to dguillett1 * * *


This assumes you do not know the start row or column of the source
sheet or the length of each column. Be sure to save your file as
an .xls or .xlsM file for macros.
'=============
Option Explicit
Sub CopyColumnsToOneColumnSAS()


Dim ss As Worksheet
Dim ds As Worksheet
Dim fr As Long 'find first row in souce sheet
Dim fc As Long 'find first column
Dim i As Long ' number of times to do it
Dim slr As Long 'find last row for each column
Dim dlr As Long 'find next available row in destination


Set ss = Sheets("sheet1")
Set ds = Sheets("sheet2")
Application.ScreenUpdating = False
ds.Columns(2).Clear
fr = ss.Cells.Find(What:="*").Row + 1 * '7 row 7
fc = ss.Cells.Find(What:="*").Column * '4 col D
For i = fc To ss.Cells(fr, Columns.Count).End(xlToLeft).Column
slr = ss.Cells(Rows.Count, i).End(xlUp).Row * ;row 40
dlr = ds.Cells(Rows.Count, 2).End(xlUp).Row + 1
ss.Cells(fr, i).Resize(slr).Copy ds.Cells(dlr, 2)
Next i
Application.ScreenUpdating = True
End Sub- Hide quoted text -


- Show quoted text -


Thanks Don. It works perfectly.
However, what if I want to have it columns specifics (column D to S
only) and starts at a specific row (row 7 in my case).
Indeed, my report will then include titles and additional columns that
I don't want to have copied to "Sheet2".


I wrote it as if you did NOT know which to use so just change
fr = 7 'ss.Cells.Find(What:="*").Row + 1
fc = 4 'ss.Cells.Find(What:="*").Column
For i = fc To 19 ' ss.Cells(fr, Columns.Count).End(xlToLeft).Column- Hide quoted text -

- Show quoted text -


Thanks.
One last question. What should I change if I need to change the
destination on "Sheet2" from cell B2 to C6.
I was able to change the column to C, but I don't know how to change
the row to start at 6. See below what I have:

Sub Copy()
Dim ss As Worksheet
Dim ds As Worksheet
Dim fr As Long 'find first row in souce sheet
Dim fc As Long 'find first column
Dim i As Long ' number of times to do it
Dim slr As Long 'find last row for each column
Dim dlr As Long 'find next available row in destination

Set ss = Sheets("Sheet1")
Set ds = Sheets("Sheet2")
Application.ScreenUpdating = False
ds.Columns(3).Clear
fr = 7 'starting row 7
fc = 4 'starting column 4 (D)
For i = fc To 19 'finishing colum S
slr = ss.Cells(Rows.Count, i).End(xlUp).Row
dlr = ds.Cells(Rows.Count, 3).End(xlUp).Row + 1 '3 corresponds to
column C on destination
ss.Cells(fr, i).Resize(slr).Copy ds.Cells(dlr, 3) '3 corresponds
to column C on destination
Next i
Application.ScreenUpdating = True
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
loop to copy paste Norvascom Excel Programming 1 October 4th 11 03:57 PM
copy paste loop---new to vba MFR Excel Programming 4 October 26th 06 08:25 PM
Copy and Paste using a loop bestie via OfficeKB.com Excel Programming 0 August 3rd 06 08:57 AM
Copy/Paste Loop Jelly''s Excel Programming 0 December 6th 05 10:10 PM
copy and paste loop Dillonstar[_5_] Excel Programming 1 December 11th 03 04:22 PM


All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"