Copy, transpose and move using VBA

nishant_kotian

New Member
Joined
Sep 25, 2011
Messages
6
I have a data range from lets say A5:A15.

I wanted to copy(capture) this data from Sheet 1 on to Sheet 2 lets say from A1:J1 in a transposed format(on sheet 2).

However once I change the data from A5:A15 on sheet 1 and again run the macros, it should now be captured on Sheet 2 from A2:J2 in a transposed format again.

Your help is highly appreciated.

Thanks in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this (A5:A15 is 11 rows so the transpose covers A:K not A:J as you posted):
Code:
Sub CopyAndTransposeData()
Dim sh1 As Worksheet, sh2 As Worksheet, r1 As Range, lRw As Long

Set sh1 = ThisWorkbook.Sheets("Sheet1")
Set sh2 = ThisWorkbook.Sheets("Sheet2")
Set r1 = sh1.Range("A5:A15")
lRw = sh2.Range("A" & Rows.Count).End(xlUp).Row
r1.Copy
With sh2
    If IsEmpty(.Range("A1")) Then
        .Range("A" & lRw).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    Else
        .Range("A" & lRw + 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    End If
End With
Application.CutCopyMode = False
End Sub
 
Upvote 0
Here is another macro for you to try...

Code:
Sub CopyAndTransposeData()
  Dim LastRow As Long, SourceRange As Range, Destination As Worksheet
  
  Set SourceRange = Sheets("Sheet1").Range("A5:A15")
  Set Destination = Sheets("Sheet2")
  
  On Error Resume Next
  LastRow = Destination.Columns("A").Resize(, SourceRange.Count).Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
  Destination.Cells(LastRow + 1, "A").Resize(, SourceRange.Count).Value = WorksheetFunction.Transpose(SourceRange)
End Sub
 
Upvote 0
Here is a modification to my previously posted code that gives you a little more flexibility in setting the destination column location (just change the two Set statements to match your actual setup)...

Code:
Sub CopyAndTransposeData()
  Dim LastRow As Long, SourceRange As Range, DestinationStartColumn As Range
 
  Set SourceRange = Sheets("Sheet1").Range("A5:A15")
  Set DestinationStartColumn = Sheets("Sheet2").Columns("A")
 
  On Error Resume Next
  LastRow = DestinationStartColumn.Resize(, SourceRange.Count).Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
  Intersect(Rows(LastRow + 1), DestinationStartColumn.Resize(, SourceRange.Rows.Count)).Value = WorksheetFunction.Transpose(SourceRange)
End Sub
 
Upvote 0
Try this (A5:A15 is 11 rows so the transpose covers A:K not A:J as you posted):
Code:
Sub CopyAndTransposeData()
Dim sh1 As Worksheet, sh2 As Worksheet, r1 As Range, lRw As Long

Set sh1 = ThisWorkbook.Sheets("Sheet1")
Set sh2 = ThisWorkbook.Sheets("Sheet2")
Set r1 = sh1.Range("A5:A15")
lRw = sh2.Range("A" & Rows.Count).End(xlUp).Row
r1.Copy
With sh2
    If IsEmpty(.Range("A1")) Then
        .Range("A" & lRw).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    Else
        .Range("A" & lRw + 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    End If
End With
Application.CutCopyMode = False
End Sub

Thanks a ton buddy!!!
 
Upvote 0
Try this (A5:A15 is 11 rows so the transpose covers A:K not A:J as you posted):
Code:
Sub CopyAndTransposeData()
Dim sh1 As Worksheet, sh2 As Worksheet, r1 As Range, lRw As Long

Set sh1 = ThisWorkbook.Sheets("Sheet1")
Set sh2 = ThisWorkbook.Sheets("Sheet2")
Set r1 = sh1.Range("A5:A15")
lRw = sh2.Range("A" & Rows.Count).End(xlUp).Row
r1.Copy
With sh2
    If IsEmpty(.Range("A1")) Then
        .Range("A" & lRw).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    Else
        .Range("A" & lRw + 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
    End If
End With
Application.CutCopyMode = False
End Sub
Thanks a ton buddy!!!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,328
Members
452,907
Latest member
Roland Deschain

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