Copy and Paste/Transpose to another sheet

Leelabird
Lounger
Posts: 28
Joined: 14 Aug 2016, 00:01

Copy and Paste/Transpose to another sheet

Post by Leelabird »

Greetings All,

I was just wondering if it is possible to copy a horizontal range (D6:S6) from one sheet (Sheet1), paste it to a cell (P10) on another sheet (Sheet2) but transpose it to the vertical. It is statistical data which is transferred to P10 and down which then has more calculations done in the following columns by formulas which are already in place. The values from P10 down align with their respective formulas in the following rows/columns. Column P is always empty. I've been trying this over a few days now and I can't work this out so I meekly ask for your assistance again :grin:
What I've tried so far seems to make the transferred data disappear through the top of the sheet with only one cell value (S6) showing in P1 on Sheet2 :scratch:
If it is possible, would it also be possible for the macro to take the User to Sheet2, P10 on completion of the transfer?

Thank you for any and all help.

Kind regards,
Leela.

vcoolio
NewLounger
Posts: 10
Joined: 15 Jan 2017, 09:45

Re: Copy and Paste/Transpose to another sheet

Post by vcoolio »

Hello Leela,

I think that you are pretty familiar with how to implement codes, so try the following:-

Code: Select all

Sub Test()
    
    Sheet1.[D6:S6].Copy
    Sheet2.[P10].PasteSpecial xlValues, Transpose:=True
    
    Application.CutCopyMode = False
    Application.Goto Sheet2.[P10]
    
End Sub
I'm not sure if you are referencing sheet names or sheet codes, so you may have to change the sheet references to suit.

I hope that this helps.

Cheerio,
vcoolio.

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Copy and Paste/Transpose to another sheet

Post by snb »

Code: Select all

Sub M_snb()
  [sheet2!P10:P26]=[transpose(sheet1!D6:S6)].Value
End Sub
Last edited by snb on 09 Jun 2023, 12:42, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Copy and Paste/Transpose to another sheet

Post by HansV »

@snb:

Shouldn't P10:B26 be P10:P25 ?
Best wishes,
Hans

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Copy and Paste/Transpose to another sheet

Post by snb »

My permission to adapt to local circumstances. ;)

User avatar
HansV
Administrator
Posts: 78558
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Copy and Paste/Transpose to another sheet

Post by HansV »

:doh:
Best wishes,
Hans

Leelabird
Lounger
Posts: 28
Joined: 14 Aug 2016, 00:01

Re: Copy and Paste/Transpose to another sheet

Post by Leelabird »

Greetings,

Thank you SNB, HansV and Vcoolio for the replies.

@SNB:
Thank you for taking an interest in helping with my query. Your code returns an "Object Required" error. I used the adjustment that HansV suggested and it returned the same error. I then removed the .Value part at the end of your code and, still using HansV's adjustment, it worked.
The [sheet2!P10:B26] part confused me as, after removing the .Value part, the code returned 15 columns x 17 rows of the transposed data with the 17th row being a #N/A error. So I suppose that it was just a typo?

@HansV:
Thank you for your input. SNB's code worked with your adjustment. I really appreciate it!

@Vcoolio:
Your code worked really well without any errors straight up! Thank you for your help and input as well.

Once again, thank you all very,very much for all the help. :thankyou:

Kind regards,
Leela.

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Copy and Paste/Transpose to another sheet

Post by snb »

Afterwards [sheet2!P10:B26] confuses me as well, since I intended to type [sheet2!P10:P26].
The eye-hand coordination appears to be rather fluffy. So let's start with new contactlenses today.

vcoolio
NewLounger
Posts: 10
Joined: 15 Jan 2017, 09:45

Re: Copy and Paste/Transpose to another sheet

Post by vcoolio »

You're welcome Leela. I'm glad that we could assist and thanks for the feed back.

@snb:
Ha. I know how you feel. I just recently had both lenses replaced in my eyes. More or less back to normal now.

Cheerio,
vcoolio.