+ Reply to Thread
Results 1 to 14 of 14

Macro to cut and paste data on the next empty row

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Macro to cut and paste data on the next empty row

    Hi, I've made a spreadsheet where sheet 2 is a calculator of sorts, I input all relevant data and the calculations are filled in via formulas. Sheet 3 is a records sheet. I'm trying to create a macro that can take all data from sheet 2 once the calculations are done and store it in sheet 3. The issue is that I need to store it in the next empty row but every time I run my macro it deletes the previous record. Also, when I cut the information from the calculator sheet I need to keep the formulas. If anyone knows how I could go about this I would very much appreciate it. I have attached some screenshots to help show you what I'm talking about.

    Screen Shot 2015-08-26 at 8.17.52 am.png
    Screen Shot 2015-08-26 at 8.23.07 am.png

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2505
    Posts
    2,790

    Re: Macro to cut and paste data on the next empty row

    It would be best if you posted your workbook.

    View Pic
    Last edited by skywriter; 08-25-2015 at 06:51 PM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Macro to cut and paste data on the next empty row

    Sub mitchellj()
        
        With Sheets(3)
            fRow = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            .Cells(fRow, 1).Value = Sheets(2).Range("B1").Value
            .Cells(fRow, 3).Value = Sheets(2).Range("B2").Value
            .Cells(fRow, 4).Value = Sheets(2).Range("D2").Value
            'and so one...
        End With
    End Sub

  4. #4
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    I'll post it now sorry!

  5. #5
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    Sheet Blank1.xlsm

    This is the sheet with all formulas. I'm trying to take all the information from sheet 2 to sheet 3, sheet 1 is not relevant to this question.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    Thanks bakerman2, I'll give it a go, I have no experience with code though so no guarantees!

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Macro to cut and paste data on the next empty row

    Or
    Sub mitchellj()
        Dim wsCalc As Worksheet: Set wsCalc = Worksheets("Calculator")
        Dim wsBet As Worksheet: Set wsBet = Worksheets("Bet Records")
        With wsBet
            fRow = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            .Cells(fRow, 1).Value = wsCalc.Range("B1").Value
            .Cells(fRow, 3).Value = wsCalc.Range("B2").Value
            .Cells(fRow, 4).Value = wsCalc.Range("D2").Value
            'and so one...
        End With
    End Sub

  8. #8
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    That seems to be working, but it doesn't clear the cell after copying and pasting it into sheet 3. Is there a way I could make it do this? I'm just not sure how to do that where the formulas are concerned as I need to clear the cell but keep the formula. Thanks again

  9. #9
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    Bakerman2

    Sorry to be a pain but I have literally no experience with this,

    What exactly do these lines of the code mean?

    Cells(fRow, 1).Value = wsCalc.Range("B1").Value
    Cells(fRow, 3).Value = wsCalc.Range("B2").Value

    I'm unsure and so I can't replicate them for the rest of the data.

    Cheers

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Macro to cut and paste data on the next empty row

    Sub mitchellj()
        Dim wsCalc As Worksheet: Set wsCalc = Worksheets("Calculator")
        Dim wsBet As Worksheet: Set wsBet = Worksheets("Bet Records")
        With wsBet
            fRow = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            .Cells(fRow, 1).Value = wsCalc.Range("B1").Value
            .Cells(fRow, 2).Value = "Exchange" 'wsCalc.Range("?").Value
            .Cells(fRow, 3).Value = wsCalc.Range("B2").Value
            .Cells(fRow, 4).Value = wsCalc.Range("D2").Value
            .Cells(fRow, 5).Value = wsCalc.Range("B5").Value
            .Cells(fRow, 6).Value = wsCalc.Range("B4").Value
            .Cells(fRow, 7).Value = wsCalc.Range("B3").Value
            .Cells(fRow, 8).Value = wsCalc.Range("B7").Value
            .Cells(fRow, 9).Value = wsCalc.Range("D7").Value
            .Cells(fRow, 10).Value = wsCalc.Range("B9").Value
            .Cells(fRow, 11).Value = wsCalc.Range("B13").Value
            .Cells(fRow, 12).Value = wsCalc.Range("B11").Value
            .Cells(fRow, 13).Value = "Profit/Loss" 'wsCalc.Range("?").Value
            .Cells(fRow, 14).Value = "Return" 'wsCalc.Range("?").Value
        End With
        With wsCalc
            Union(.Range("B1:B11"), .Range("D2"), .Range("D7"), .Range("D9"), .Range("D11"), .Range("F9")).ClearContents
        End With
    End Sub
    calculate rownumber first available empty row
    fRow = .Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    cells arguments are cells(rownumber,columnnumber)
    so if fRow = 10 then cells(fRow,1) means A10, cells(fRow,2) means B10, and so one
    Last edited by bakerman2; 08-25-2015 at 08:04 PM.

  11. #11
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    Ah okay, I used your updated code and it is almost perfect. The only issue remaining is that on the bet records sheet there is a column called exchange and I don't have a column section on the calculator sheet so when i run the macro it copies the word exchange into the exchange column. It does the same thing with 'profit/loss' and 'return (%)'. With those two it is also copying the title of the column instead of the value calculated in the calculator sheet. If you had any suggestions on how to fix this I would be eternally grateful!

    Cheers

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Macro to cut and paste data on the next empty row

    I did these things on purpose because
    1. I can't figure out which value from Calculator sheet is to be copied into Exchange column
    2.Same for Profit/Loss and Return % column

    So provide cell address on calculator sheet for these 3 columns

  13. #13
    Registered User
    Join Date
    08-24-2015
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    8

    Re: Macro to cut and paste data on the next empty row

    I used your code and tweaked it and I've got it working perfectly! Thank you so much for your help

    Cheers

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,499

    Re: Macro to cut and paste data on the next empty row

    You're welcome and thanks for the rep

+ 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. Macro to copy and paste data to next empty cell.
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2015, 10:41 AM
  2. Replies: 6
    Last Post: 10-20-2014, 09:37 AM
  3. [SOLVED] Macro-Copy and paste the new data to the next empty row on summary sheet
    By ttn2b in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-14-2014, 12:02 PM
  4. Macro to paste data to next empty cell
    By 4lowie in forum Excel General
    Replies: 1
    Last Post: 12-13-2013, 04:02 AM
  5. [SOLVED] Macro to Copy cells data and paste on next empty row
    By tfaridi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2012, 05:35 PM
  6. [SOLVED] macro to paste data untill the next empty row
    By winger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2012, 10:32 AM
  7. Editting Macro to Select Last Empty Column to Paste Data
    By Zaraf in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-05-2008, 11:40 AM

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