+ Reply to Thread
Results 1 to 5 of 5

Need VBA Code Amended to Paste in the Next Available Column

Hybrid View

  1. #1
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Need VBA Code Amended to Paste in the Next Available Column

    Hello,

    With the code shown below I am able to cut and past data via macro. It transposes the data and works perfectly, however, I would like this code to find the next available column in the "ActiveSheet" and paste, effectively appending to the existing data. In other words, if what is shown below pastes into column "L", I'd like the next iteration to find that column "M" is empty and paste the data there.

    Thanks,

    Sub Import_Data()
        Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B2:M2").Copy
       ActiveSheet.Range("L7:L18").PasteSpecial Transpose:=True
    
    End Sub

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need VBA Code Amended to Paste in the Next Available Column

    This should work

    Sub Import_Data()
        Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B2:M2").Copy
       ActiveSheet.Cells(7, Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial Transpose:=True
    End Sub
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need VBA Code Amended to Paste in the Next Available Column

    Awesome, works like a charm, many thanks!

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need VBA Code Amended to Paste in the Next Available Column

    You're welcome,
    regards, JLG

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Need VBA Code Amended to Paste in the Next Available Column

    Cech it out.

    Sub Button1_Click()
    
        Worksheets("Sheet1").Range("B2:M2").Copy
        With ActiveSheet
            .Cells(7, .Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial Transpose:=True
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VB Code to copy paste data from column to another column based on content of cell
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2019, 08:50 PM
  2. [SOLVED] VBA Code to lookup value in column then paste to right
    By Ollie7957 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2017, 07:47 AM
  3. [SOLVED] Recently amended VBA code causing saving error
    By Nitro2481 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-01-2016, 01:44 PM
  4. If less than zero, amended formula
    By pauldaddyadams in forum Excel General
    Replies: 4
    Last Post: 02-19-2015, 03:16 AM
  5. [SOLVED] Amended VBA Code to Input information into form for viewing
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2015, 06:48 AM
  6. Replies: 5
    Last Post: 08-01-2014, 04:30 PM
  7. VBA Code to copy data from last filled column and paste to the next available column.
    By Pavman2473 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2012, 09:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1