+ Reply to Thread
Results 1 to 8 of 8

Copy data and paste to last empty column

Hybrid View

hanif Copy data and paste to last... 07-12-2016, 06:06 AM
Kamboj Re: Copy data and paste to... 07-12-2016, 06:36 AM
hanif Re: Copy data and paste to... 07-12-2016, 06:52 AM
Kamboj Re: Copy data and paste to... 07-12-2016, 07:22 AM
JOHN H. DAVIS Re: Copy data and paste to... 07-12-2016, 07:47 AM
hanif Re: Copy data and paste to... 07-12-2016, 08:47 AM
hanif Re: Copy data and paste to... 07-12-2016, 09:56 AM
JOHN H. DAVIS Re: Copy data and paste to... 07-12-2016, 10:08 AM
  1. #1
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Copy data and paste to last empty column

    Hi All,

    I created a spreadsheet which opens a temporary sheet to allow you copy a range of data and it sums the data and copu the sum into a column in new sheet, (sheets("Elec HH").range("B4")) in below code, and then delete the temporary sheet and open new temporary sheet if required. right now data will be paste only in Column B (starting from B4) of the new sheet. I am looking for a way to paste the data into the last empty column instead of replacing the existing data column. Any idea how can I change the below coding to copy these data?

    Thanks alot

     Sub LoadButton()
    
        Dim lastRow As Long, rng As Range, cell As Range, lastcol As Range
        Dim waTemp As Worksheet
        Dim copydata As Long
        
        Set wsTemp = Sheets("TempElec")
        
        lastRow = Sheets("TempElec").Range("B1048576").End(xlUp).Row
        lastcol = Sheets("Elec HH").Cells(2, Columns.Count).End(xlUp).Column
    
        For r = 7 To lastRow
        
        Sheets("TempElec").Cells(r, "AX").Value = Application.WorksheetFunction.Sum(Range(Cells(r, "B"), Cells(r, "AW")))
    
        Next r
    
        'Copy and paste data
        With TempElec
          Sheets("TempElec").Range("AX7:AX" & Sheets("TempElec").Cells(Rows.Count, 49).End(xlUp).Row).Copy Sheets("Elec HH").Range("B4")
        End With
        
        '~~> Delete the temp sheet
        Application.DisplayAlerts = False
        wsTemp.Delete
        Application.DisplayAlerts = True
    
        '~~> Kill the temp file
        On Error Resume Next
        Kill TempPath & "TempChart.bmp"
        On Error GoTo 0
    
    End Sub

  2. #2
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: Copy data and paste to last empty column

    Change line to

    Sheets("TempElec").Range("AX7:AX" & Sheets("TempElec").Cells(Rows.Count, 49).End(xlUp).Row).Copy Sheets("Elec HH").Range("B") & Sheets("Elec HH").Cells(Rows.Count, "B").End(xlUp).Row
    Kamboj
    _________________________________________________________________________________
    Mark the thread as SOLVED if my answer satisfy you.

  3. #3
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: Copy data and paste to last empty column

    Thanks for your reply.

    I am getting an error "Application-defined or object-defined error"

    Any idea why?
    Quote Originally Posted by Kamboj View Post
    Change line to

    Sheets("TempElec").Range("AX7:AX" & Sheets("TempElec").Cells(Rows.Count, 49).End(xlUp).Row).Copy Sheets("Elec HH").Range("B") & Sheets("Elec HH").Cells(Rows.Count, "B").End(xlUp).Row

  4. #4
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: Copy data and paste to last empty column

    Sheets("TempElec").Range("AX7:AX" & Sheets("TempElec").Cells(Rows.Count, 49).End(xlUp).Row).Copy Sheets("Elec HH").Range("B" & Sheets("Elec HH").Cells(Rows.Count, "B").End(xlUp).Row)

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy data and paste to last empty column

    Maybe:

    Sub hanify()
    Dim x As Long
    x = Cells(4, Columns.Count).End(xlToLeft).Column + 1
    'CHANGE YOUR COPY DESTINATION FROM Sheets("Elec HH").Range("B4")
    'To
    'Sheets("Elec HH").cells(4, x)
    
    End Sub

  6. #6
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: Copy data and paste to last empty column

    Thank you both. for some reason it does not properly. I have attached the spreadsheet could you have a look to see if you understand it?

    if you click on button 1 the temporary sheet will appear. when it pops up if you just type any number and drag it to fill the table would be fine. many thanks
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    391

    Re: Copy data and paste to last empty column

    Thank you both so much with your helps I was managed to figure it out

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy data and paste to last empty column

    You're welcome. Glad to help out and that you came up with a solution.

+ 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. Copy data and paste to another column incrementing that column to next empty cell
    By edens2021 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2015, 11:43 AM
  2. copy and paste data in another column in next empty cell
    By dilippyare in forum Excel General
    Replies: 3
    Last Post: 11-24-2014, 11:11 AM
  3. [SOLVED] Copy all cells in column that contain data & paste to first empty row of another column.
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2014, 08:45 AM
  4. Copy/Paste to Next Empty Row Overwriting Previous Row When Column A Is Empty
    By grantfitz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2013, 04:34 PM
  5. Replies: 5
    Last Post: 03-02-2013, 04:22 PM
  6. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  7. Copy and paste data if row in Column N is empty.
    By Hopper in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-31-2009, 03:25 PM

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