Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copy data from one sheet to another

Start with a WB with two existing sheets: Sh1, Sh2
Sh2 contains a lot of permanent records.
Sh1 contains temporary records for transfer to Sh2.
Sh1 has a header row and 7 columns (A-G) and
variable number of records.
I want to copy all records on Sh1 then paste on
Sh2 below existing records, but, for each record
Sh1 Column "A" goes in Sh2 Column "E"
Sh1 "B" goes in Sh2 "C"
Sh1 "C" goes in Sh2 "K"
etc.
I'm thinking copy Sh1 into a Dynamic Array and
then copy to Sh2 element by element?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy data from one sheet to another

Sh1 Column "A" goes in Sh2 Column "E"
Sh1 "B" goes in Sh2 "C"
Sh1 "C" goes in Sh2 "K"


Where does Sh1 columns E go for example if your putting A in column E?

Perhaps you should complete this table

Sh1 Sh2
A E
B C
C K
D ?
E ?
F ?
G ?


Mike

"John Pierce" wrote:

Start with a WB with two existing sheets: Sh1, Sh2
Sh2 contains a lot of permanent records.
Sh1 contains temporary records for transfer to Sh2.
Sh1 has a header row and 7 columns (A-G) and
variable number of records.
I want to copy all records on Sh1 then paste on
Sh2 below existing records, but, for each record
Sh1 Column "A" goes in Sh2 Column "E"
Sh1 "B" goes in Sh2 "C"
Sh1 "C" goes in Sh2 "K"
etc.
I'm thinking copy Sh1 into a Dynamic Array and
then copy to Sh2 element by element?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copy data from one sheet to another



Sh1 Sh2
A E
B C
C K
D A
E F
F H
G G
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy data from one sheet to another

Hi,

This is Sh1 worksheet code and assumes Sh2 is called Sheet2

Sub MoveIt()
Dim SourceColumn As Long
Dim DestinationColumn As Long
Dim LastRow As Long
For SourceColumn = 1 To 7
LastRow = Cells(Rows.Count, SourceColumn).End(xlUp).Row
Range(Cells(2, SourceColumn), Cells(LastRow, SourceColumn)).Copy
Select Case SourceColumn
Case Is = 1
DestinationColumn = 5
Case Is = 2
DestinationColumn = 3
Case Is = 3
DestinationColumn = 11
Case Is = 4
DestinationColumn = 1
Case Is = 5
DestinationColumn = 6
Case Is = 6
DestinationColumn = 8
Case Is = 7
DestinationColumn = 7
End Select
LastRow = Sheets("Sheet2").Cells(Rows.Count, DestinationColumn).End(xlUp).Row
Sheets("Sheet2").Cells(LastRow + 1, DestinationColumn).PasteSpecial
Next

Mike

"John Pierce" wrote:



Sh1 Sh2
A E
B C
C K
D A
E F
F H
G G

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy data from one sheet to another

oops,
the
End Sub

is missing

Mike

"Mike H" wrote:

Hi,

This is Sh1 worksheet code and assumes Sh2 is called Sheet2

Sub MoveIt()
Dim SourceColumn As Long
Dim DestinationColumn As Long
Dim LastRow As Long
For SourceColumn = 1 To 7
LastRow = Cells(Rows.Count, SourceColumn).End(xlUp).Row
Range(Cells(2, SourceColumn), Cells(LastRow, SourceColumn)).Copy
Select Case SourceColumn
Case Is = 1
DestinationColumn = 5
Case Is = 2
DestinationColumn = 3
Case Is = 3
DestinationColumn = 11
Case Is = 4
DestinationColumn = 1
Case Is = 5
DestinationColumn = 6
Case Is = 6
DestinationColumn = 8
Case Is = 7
DestinationColumn = 7
End Select
LastRow = Sheets("Sheet2").Cells(Rows.Count, DestinationColumn).End(xlUp).Row
Sheets("Sheet2").Cells(LastRow + 1, DestinationColumn).PasteSpecial
Next

Mike

"John Pierce" wrote:



Sh1 Sh2
A E
B C
C K
D A
E F
F H
G G



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Copy data from one sheet to another

Select Case SourceColumn
Case Is = 1
DestinationColumn = 5
Case Is = 2
DestinationColumn = 3
Case Is = 3
DestinationColumn = 11
Case Is = 4
DestinationColumn = 1
Case Is = 5
DestinationColumn = 6
Case Is = 6
DestinationColumn = 8
Case Is = 7
DestinationColumn = 7
End Select


An alternate to (that is, replacement for) the above section of your code
that the OP may want to consider using is this single line statement...

DestinationColumn = Choose(SourceColumn, 5, 3, 11, 1, 6, 8, 7)

--
Rick (MVP - Excel)


"Mike H" wrote in message
...
Hi,

This is Sh1 worksheet code and assumes Sh2 is called Sheet2

Sub MoveIt()
Dim SourceColumn As Long
Dim DestinationColumn As Long
Dim LastRow As Long
For SourceColumn = 1 To 7
LastRow = Cells(Rows.Count, SourceColumn).End(xlUp).Row
Range(Cells(2, SourceColumn), Cells(LastRow, SourceColumn)).Copy
Select Case SourceColumn
Case Is = 1
DestinationColumn = 5
Case Is = 2
DestinationColumn = 3
Case Is = 3
DestinationColumn = 11
Case Is = 4
DestinationColumn = 1
Case Is = 5
DestinationColumn = 6
Case Is = 6
DestinationColumn = 8
Case Is = 7
DestinationColumn = 7
End Select
LastRow = Sheets("Sheet2").Cells(Rows.Count,
DestinationColumn).End(xlUp).Row
Sheets("Sheet2").Cells(LastRow + 1, DestinationColumn).PasteSpecial
Next

Mike

"John Pierce" wrote:



Sh1 Sh2
A E
B C
C K
D A
E F
F H
G G


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Copy data from one sheet to another

Thanks Mike and Rick.
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
copy rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
copy data of two cells from Sheet 2 into one cell in Sheet 1 cahabbinga Excel Worksheet Functions 6 January 30th 08 01:00 PM
How can i copy data from a tabbed working sheet to a summary sheet StephenF Excel Discussion (Misc queries) 1 March 15th 07 03:40 PM
how to copy a cell with formula from sheet 1 (data is all vertical) into sheet 2 parag Excel Worksheet Functions 3 June 15th 06 10:29 PM
Copy data from sheet 1 to sheet 2 based on day/date [email protected] Excel Programming 7 October 1st 05 04:59 PM


All times are GMT +1. The time now is 08:17 AM.

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

About Us

"It's about Microsoft Excel"