How to copy and paste in a loop in a set of 3 cells

cubs786

New Member
Joined
May 28, 2019
Messages
4
Hi,

I have an excel with lots of data but the data is in columns (each column has 10,000 or more data points), such as:

7.52
7.56
7.56
7.55
7.35

and I want copy the first three cells and transpose them on a different excel file, such as

7.52, 7.56, 7.56
7.56, 7.55, 7.35

But I want to do the whole column instead of manually copying and pasting three cells at a time.

I will be using a macro to do this job.

I know how to copy and paste the first three cells using macro but I want to continue all of the data to run in a loop to finish the job automatically or there is any other to do this?

thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The source column 1, do you want it in the destination columns 1,2 and 3, where do you want the origin column 2, in destination columns 4,5 and 6?How many origin columns do you have?
 
Upvote 0
Via Non-Macro:

If you put this formula in the first cell where you want the result(s) to be, fill across 2 more cells so you have the formula in 3 cells, then fill down as many as the (#rows)/3 or until you get all 0s in the rows.

Code:
=INDEX($A:$A,ROW(A1)*3-3+COLUMN(A1))

You could incorporate a test for all 0s and blank them or do whatever.
 
Last edited:
Upvote 0
If so, try this
change sheet1 by the name of your source sheet

(2 columns with 10,000 records each, processed in 5 seconds)

Code:
Sub set3column()
    Dim l1 As Workbook, l2 As Workbook, sh1 As Worksheet, sh2 As Worksheet
    Dim i As Long, j As Long, k As Long, c As Long
    
    Application.ScreenUpdating = False
    Set l1 = ThisWorkbook
    Set sh1 = l1.Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
    Set l2 = Workbooks.Add
    Set sh2 = l2.Sheets(1)
    
    c = 1
    For j = 1 To sh1.Cells(1, Columns.Count).End(xlToLeft).Column
        k = 1
        For i = 1 To sh1.Cells(Rows.Count, j).End(xlUp).Row Step 3
            sh2.Cells(k, c).Resize(1, 3).Value = WorksheetFunction.Transpose(sh1.Cells(i, j).Resize(3, 1).Value)
            k = k + 1
        Next
        c = c + 3
    Next
    MsgBox "End"
End Sub
 
Upvote 0
I had a different macro approach which seemed to work if I understand the OP correctly.

Code:
Sub TransposeBy3()
Dim LR As Long
LR = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
LR = LR / 3
Sheets("Sheet1").Range("C1:E1").Formula = "=INDEX($A:$A,ROW(A1)*3-3+COLUMN(A1))"
Range("C1:E1").Select
Selection.AutoFill Destination:=Range("C1:E" & LR)
End Sub
 
Upvote 0
The source column 1, do you want it in the destination columns 1,2 and 3, where do you want the origin column 2, in destination columns 4,5 and 6?How many origin columns do you have?

column A

7.52
7.56
7.56
7.55
7.35

I want to have it in the same excel file


B C D
7.52, 7.56, 7.56
7.56, 7.55, 7.35

Hopefully it clears it up



 
Upvote 0
AH, the 3rd value becomes the first in the next set of 3 transpositions?!?!?
 
Upvote 0
I apologize for the typo but it should be the fourth one.

7.52

7.56
7.56
7.55
7.35
7.25


B C D
7.52, 7.56, 7.56
7.55, 7.35, 7.25
 
Upvote 0
Then I think my formulas or my macro will do it for you, right? I just tried 10005 cells and the macro did it instantaneously.
 
Upvote 0
Thanks, it's working perfectly fine. but is there a way to add if and else statement to take out the zeros at the end.

73.5390673.5363673.5579673.4402873.4868573.5303373.5829573.49767
73.532873.4808773.5378873.5000173.5157273.5608173.5301373.52189
73.4784373.5699873.5552973.4990773.5003373.5574773.5135673.55635
73.5529973.5305373.5628873.5265473.4967373.5394273.547273.54499
73.5458973.5299473.5325573.4789773.5184573.4804273.5283773.49318
73.5463673.5028673.4979373.504173.5424973.4872773.4614573.48816
73.5312973.5604573.5472673.4576973.5102373.5089273.5871673.49274
73.5008273.52829000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000

<colgroup><col width="72" span="8" style="width:54pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,988
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top