Transpose to every other cell

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
I have this as part of my code:

Code:
Sheets("Data").Range("I5:I9").Copy
Sheets("Totals").Range("G3").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True

How can I make it Paste to every other column starting in G3?

If I can get help on this part, I guess I can adapt it to copy the verticle range O5:O9 and Paste starting at H3 (every other col)

Thanks
Harry
 
Ummm

I'm trying to understand the codes.

I just tried the code without using array and because col O has formulas, it gives me a #VALUE! when pasted to the Totals sheet.
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If you want to copy/paste formula then you need to use PasteSpecial, I think...
Code:
Sub test2()
Dim r As Range, n As Long
With Sheets("data").Range("i5:i9")
     For Each r In .Cells
          r.Copy Sheets("result").Range("g3").Offset(,n)
          r.Offset(,6).Copy
          Sheets("result").Range("g3").Offset(,n+1).PasteSpecial xlPasteFormulas
          n = n + 2
     Next
End With
End Sub
 
Upvote 0
If the above doesn't work, try
Code:
Sub test2()
Dim a(1 To 10), n As Long, i As Long
n = 1
For i = 5 To 9
     a(n) = Sheets("data").Range("i" & i).Value
     a(n + 1) = Sheets("data").Range("o" & i).Formula
     n = n + 2
Next
Sheets("totals").Range("g3").Resize(,10).Value = a
End Sub
Note
In this case, forumal should be written with the sheet reference clearly even the formula is referencing the cell(s) within the same sheet.
 
Upvote 0
Then change

xlPasteFormulas to

xlPasteValues

Or
Code:
Sub test()
Dim r As Range, n As Long
For Each e In Sheets("data").Range("i5:i9")
     Sheets("totals").Range("g3").Offset(,n).Value = r.Value
     Sheets("totals").Range("g3").Offset(,n+1).Value = r.Offset(,6).Value
     n = n + 2
Next
End Sub
 
Upvote 0
Sorry, I think this thread is getting a little too long and confusing.

This works just fine:
Code:
Sub test4()
    Dim a(1 To 10), n As Long, i As Long
    n = 1
        For i = 5 To 9
        a(n) = Sheets("data").Range("i" & i).Value
         a(n + 1) = Sheets("data").Range("o" & i).Value
         n = n + 2
Next
    Sheets("totals").Range("g3").Resize(, 10).Value = a
End Sub

I was just trying to understand your without using array formula:
Code:
Sub test2() 
Dim r As Range, n As Long 
With Sheets("data").Range("i5:i9") 
     For Each r In .Cells 
          r.Copy Sheets("result").Range("g3").Offset(,n) 
          r.Offset(,6).Copy Sheets("result").Range("g3").Offset(,n+1) 
          n = n + 2 
     Next 
End With 
End Sub
Which gave me the #VALUE! error from col "O" because it is a formula.
 
Upvote 0
Have tried this one?
Code:
Sub test()
Dim r As Range, n As Long
For Each e In Sheets("data").Range("i5:i9")
     Sheets("totals").Range("g3").Offset(,n).Value = r.Value
     Sheets("totals").Range("g3").Offset(,n+1).Value = r.Offset(,6).Value
     n = n + 2
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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