VB code for copying entire rows from mulitple worksheets into a worksheet

Joined
Mar 9, 2008
Messages
1
Reaction score
0
Hi,
I have large amount of data in 3 separate worksheets ('Segment 1", "Segment 2", "Segment 3") that I need to copy and paste values into a fourth worksheet called, "CSV-Data" in the following way:

CSV-Data.Row1=Segment 1.Row1
CSV-Data.Row2=Segment 2.Row1
CSV-Data.Row3=Segment 3.Row1

CSV-Data.Row4=Segment 1.Row2
CSV-Data.Row5=Segment 2.Row2
CSV-Data.Row6=Segment 3.Row2
.....
To achieve above my code is currently as shown below:
Code:

Sheets("Segment 1").Select
Rows("2:2").Select
Selection.Copy
Sheets("CSV-Data").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Segment 2").Select
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("CSV-Data").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Segment 3").Select
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("CSV-Data").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Segment 1").Select
Rows("3:3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("CSV-Data").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Segment 2").Select
Rows("3:3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("CSV-Data").Select
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Segment 3").Select
Rows("3:3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("CSV-Data").Select
Range("A6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

/Code

I NEED TO USE VARIABLES SO THAT THE CODE GOES THROUGH EACH ROW OF ALL WORKSEETS AND LOOP THROUGH TO COPY AND PASTE VALUES UNTIL IT FINDS NO VALUES FROM WORKSHEETS 1,2, AND 3. Total number of rows in each worksheet is same.

Please help.

Thanks,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top