VBA copy destination transpose

henrik2h

Board Regular
Joined
Aug 25, 2008
Messages
155
Office Version
  1. 2021
Platform
  1. Windows
Can't really find an answer, perhaps it is not possible? I am trying the following in VBA.

I have a range A1:AB10 (rng1) on sheet1 (always the same size). I want to copy that and transpose it and place it in sheet2 (rng2).

Then the loop runs again and I am then going to copy rng1 again, transpose it and and place it UNDER the first values on sheet2.

However, I do not want to use copy - pastespecial! Preferably I want the data directly (i.e. rng2(offset) = rng 1) OR using copy destination.

It is already in a loop so no problem having a variable change for an offset-statement. Is it possible to use the copy methods above together with "transpose"? How would that line look like?

like this, if you see what I mean

rng2.offset(j,0). = rng1.transpose
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
OK, I might have got around it. However, now my source range is not recalculated. The same values are pasted into the target each time. Any ideas?


Code:
' Calculate all leases and copy to Pivot sheet
'
'
    Application.ScreenUpdating = False
    Application.Iteration = False
    Dim i As Integer, j As Integer, Lease_Count As Integer, PivotSource As Range, PivotTarget As Range, PivotSourceTrans As Variant, msg As String
    
    Set PivotTarget = Sheets("Pivot").Range("A8:aj138")
    Set PivotSource = Sheets("Flow_calculation").Range("AC225:FC260")
    PivotSourceTrans = Application.WorksheetFunction.Transpose(PivotSource)
    
    Sheets("Pivot").Range("A8:AJ1000000").ClearContents

     Lease_Count = Sheets("Input_by_premises").ListObjects("tbRentRoll").DataBodyRange.Rows.Count

        
    'Calculate for all leases, one by one
    For i = 1 To Lease_Count
    
    ' Offset target range to put values after each other
    j = (i - 1) * 131
    
    'Choose lease from row i, this should trigger a calculation and new PivotSource
    Sheets("Flow_calculation").Range("b3").Value = i

        
    'Copy cash flow data from lease and add to pivot sheet
    PivotTarget.Offset(j, 0) = PivotSourceTrans
    
  
    Next i

    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True


End Sub
 
Last edited:
Upvote 0
Putting the PivotSourceTrans = Application.WorksheetFunction.Transpose(PivotSource) inside the loop solved it.
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,693
Members
452,667
Latest member
vanessavalentino83

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