Copying from one Worksheet to another repeatedly.

qh017

New Member
Joined
May 20, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I would like to copy from Cells O4:O9 in Sheet 1. The destination would be a transposed paste result into A1:F1 in Sheet 2. I would like the information to remain their temporarily. Then, if I run the macro again, I would like it to copy the new data in O4:O9, but this time paste into A2:F2 on Sheet 2 (not overwrite previous copy). If I were to run macro a third time, it would copy into A3:F3, and so on.

If Sheet 2 were to be cleared, the macro would paste into A1:F1 again.

I am sure this is possible, but I have been unable to figure it out. I am very new to using macros and VBA. I tried finding a solution online, but was unable to find a resource answering this question.

Thank you in advance for any advice offered.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Possibly something like this.
VBA Code:
Sub CopyAndTranspose()
    Dim LastRow As Long
    With Worksheets("Sheet2")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        If Len(.Range("A1").Value) > 0 Then
            LastRow = LastRow + 1
        End If
        Worksheets("Sheet1").Range("O4:O9").Copy
        .Range("A" & LastRow).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    End With
End Sub
 
Upvote 1
Solution
Well, I already made it, so I might as well offer it, just to give you options:
VBA Code:
Sub CopyRangeToNextRow()
    Dim CopyRange As Range, PasteRange As Range
    Set CopyRange = ThisWorkbook.Sheets(1).Range("O4:O9")
    
    Dim PasteRow As Long
    
    With ThisWorkbook.Sheets(2)
        If WorksheetFunction.Sum(.Range("A1:F1")) = 0 Then
            PasteRow = 1
        Else
            PasteRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
        End If
        
        Set PasteRange = .Range(.Cells(PasteRow, 1), _
                                .Cells(PasteRow, 6))
        PasteRange.Value2 = WorksheetFunction.Transpose(CopyRange)
    End With
        
    End Sub
 
Upvote 0
Possibly something like this.
VBA Code:
Sub CopyAndTranspose()
    Dim LastRow As Long
    With Worksheets("Sheet2")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        If Len(.Range("A1").Value) > 0 Then
            LastRow = LastRow + 1
        End If
        Worksheets("Sheet1").Range("O4:O9").Copy
        .Range("A" & LastRow).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    End With
End Sub
Thank you very much. This worked great :)
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,155
Members
452,615
Latest member
bogeys2birdies

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