Consulting

Results 1 to 8 of 8

Thread: Add Transpose to line of code

  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    12
    Location

    Add Transpose to line of code

    Hi can anyone help?

    I want to add transpose to the Copy ToSht.Range, is there a way to do this?

    Private Sub CommandButton3_Click()
    
        Set FromSht = Sheets("Sheet1")
        Set ToSht = Sheets("Sheet2")
        
        r = 2
        
        While FromSht.Cells(r, "A") <> "" And FromSht.Cells(r, "C") <> ""
            
        r = r + 1
        
        Wend
        
        If FromSht.Cells(r, "A") <> "" Then
            
        FromSht.Cells(r, "C") = 1
            
        FromSht.Range("A" & r & ":B" & r).Copy ToSht.Range("AK20:AL20")
        
        End If
    
    End Sub
    I would like the copy to transpose to AK20:AK21


    Any help would be apprieciated

    Regards

    pwill32
    Last edited by pwill32; 06-30-2017 at 12:39 PM.

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello pwill32,

    You need to use PasteSpecial...

    Private Sub CommandButton3_Click() 
         
        Set FromSht = Sheets("Sheet1") 
        Set ToSht = Sheets("Sheet2") 
         
        r = 2 
         
        While FromSht.Cells(r, "A") <> "" And FromSht.Cells(r, "C") <> "" 
             
            r = r + 1 
             
        Wend 
         
        If FromSht.Cells(r, "A") <> "" Then 
             
            FromSht.Cells(r, "C") = 1 
             
            FromSht.Range("A" & r & ":B" & r).Copy 
            ToSht.Range("AK20:AL20").PasteSpecial Paste:=xlPasteAll, Transpose:=True 
             
        End If 
         
    End Sub
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    VBAX Regular
    Joined
    Jun 2017
    Posts
    12
    Location
    Quote Originally Posted by Leith Ross View Post
    Hello pwill32,

    You need to use PasteSpecial...

    Private Sub CommandButton3_Click() 
         
        Set FromSht = Sheets("Sheet1") 
        Set ToSht = Sheets("Sheet2") 
         
        r = 2 
         
        While FromSht.Cells(r, "A") <> "" And FromSht.Cells(r, "C") <> "" 
             
            r = r + 1 
             
        Wend 
         
        If FromSht.Cells(r, "A") <> "" Then 
             
            FromSht.Cells(r, "C") = 1 
             
            FromSht.Range("A" & r & ":B" & r).Copy 
            ToSht.Range("AK20:AL20").PasteSpecial Paste:=xlPasteAll, Transpose:=True 
             
        End If 
         
    End Sub


    Hi Leith Ross,

    yes that works

    thanks for your help,

    much apprieciated

    pwill32

  4. #4
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello pwill32,

    You should let others know if you have posted your question in other forums. I see that you posted this same question at Mr Excel. I did not see the post until after I had posted my answer. The two answers are the same. However, there was no need for me to post an answer since your question had already been answered.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    @pwill32 --

    For more info about the right way to multi-post ...


    http://www.vbaexpress.com/forum/faq...._new_faq_item3
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Jun 2017
    Posts
    12
    Location
    Hi Leith Ross,

    Sorry about that, no disrespect intended, I didn't know I could have links to show I have asked on other forums?
    I will make sure I do this in future

    Perhaps you could help me? I have just added a post to mrexcel and want to ask the same question here, do I just copy the address in the browser and paste it here?

    Regards

    pwill32

  7. #7
    VBAX Regular
    Joined
    Jun 2017
    Posts
    12
    Location
    Thanks Paul_Hossler

    Regards

    pwill32

  8. #8
    VBAX Regular
    Joined
    Jun 2017
    Posts
    12
    Location
    Hi,
    sorry, didn't know about this rule, no disrespect intended.
    I have asked this question on another forum and it has been answered.
    https://www.mrexcel.com/forum/excel-...line-code.html

    regards

    pwill32
    Quote Originally Posted by Leith Ross View Post
    Hello pwill32,

    You should let others know if you have posted your question in other forums. I see that you posted this same question at Mr Excel. I did not see the post until after I had posted my answer. The two answers are the same. However, there was no need for me to post an answer since your question had already been answered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •