Macro for copying and pasting data to another area without overwriting last rows

Postmaster383

New member
Joined
Jul 7, 2021
Messages
9
Reaction score
0
Points
0
Excel Version(s)
2013
[FONT=&quot]I'm on a ship and I have a spreadsheet which I update daily at Noon, mainly for fuel and gas consumption. I have a hidden row which mirrors various data around the spreadsheet which is generated from various formula around the spreadsheet, this data is cell range Q56:Y56.[/FONT]

[FONT=&quot]I want to click the "Noon" button and for the data to copy into the next available row in the table range Q:Y rows 4 to 53. I don't want it overwriting previous data but copying into the next blank row. So the data being copied and pasted is within the same worksheet.

[/FONT]
[FONT=&quot]The various data I want to copy is in cells Q56:Y56 (not in the image below) and I want to press the NOON button and for it to paste into the next available row in my table (rather than manually entering it each day). So for Jul 6, it would paste into Row 20 columns Q:Y. If I was to press multiple times it would keep filling up the next available row to a maximum of Row 53 columns Q to Y. I don't think it's possible to record a macro to simulate this so will need some extra code.
Thanks in advance for any help given. [/FONT]
 

Attachments

  • Capture.jpg
    Capture.jpg
    111.3 KB · Views: 17
A picture doesn't provide the best information to create a response to your request. You can click the GO ADVANCED button in the REPLY window (lower right) and attach a copy of your workbook.
 
A picture doesn't provide the best information to create a response to your request. You can click the GO ADVANCED button in the REPLY window (lower right) and attach a copy of your workbook.

Hi, thanks for replying. I've attached a copy of this workbook. Every day the spreadsheet is copied and renamed and updated for every voyage.
Thanks
 

Attachments

  • 05.NOON Jul 5, 2021.xlsm
    50.5 KB · Views: 10
I'm having great difficulty determining which cells the following information is located. You have a very busy table on the left side.

Can you specify which cell populates the following readings ?


Reading TypeCx
Date / TimeHrsObs MilesEnter RPMEnter Slip (%)Enter Speed (kn)Enter HFO Cons (MT)Enter Noon HFO ROB (MT)Enter LSDO Cons (MT)Enter Noon LSDO ROB (MT)Enter LNG Cons (MT)
 
I'm having great difficulty determining which cells the following information is located. You have a very busy table on the left side.

Can you specify which cell populates the following readings ?


Reading TypeCxDate / TimeHrsObs MilesEnter RPMEnter Slip (%)Enter Speed (kn)Enter HFO Cons (MT)Enter Noon HFO ROB (MT)Enter LSDO Cons (MT)Enter Noon LSDO ROB (MT)Enter LNG Cons (MT)

Hello,

Ignore everything on the left hand side. If you go down to row 56 there are a set of values. From columns Q to Y. I want these copied into the same columns in the table directly above. This is everything from Obs Miles to Enter LNG Cons (MT). The spreadsheet is being copied and renamed new every day so as time progresses the table will fill up. The idea is, instead of manually typing these figures in the table each day, pressing the Noon button to simply copy and paste the daily values in row 56 to the next available row in the table (without deleting any other data). So in the example I gave you, the numbers should paste into row 20 in same columns. If I pressed Noon a 2nd time it would go into row 21 and so on.
30251.18 rpm3.8%12.080001906.07 52.48
 
Ok ... it's beginning to make more sense.

Where does the data for Cols M:p come from ? Seems you would want to automate the entry of those cols as well.
 
Ok ... it's beginning to make more sense.

Where does the data for Cols M:p come from ? Seems you would want to automate the entry of those cols as well.

Those can't really be automated as we don't always take readings at Noon. For example when the voyage ends it's called End of Passage (EOP) so would manually select. Add the time and date manually. As the clocks change this is represented by -1, 0, or 1. The No of hours always has formula so basically it's only Q to Y. Also, for now, we don't have any HFO (heavyfuel oil) on board so the spreadsheet was modified but there's a chance we may get some in the future. So for now those will always be zero.
 
Ok ... give me a little time.
 
Ok .. this one method. There are plenty of ways to accomplish your goal ... this is only one.

Code:
Sub CopyOwnTab()Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim ws As Worksheet
Dim ans As String


Set ws = ActiveSheet


On Error GoTo M


Lastrow = Sheets("NOON Figs").Cells(Rows.Count, "Q").End(xlUp).Row


    For i = 2 To Lastrow
    ans = Sheets("NOON Figs").Cells(i, 17)
        Sheets("NOON Figs").Cells(i, 17).Resize(, 9).Copy
            
            For Each cell In ws.Columns(17).Cells
                If IsEmpty(cell) = True Then cell.Select: Exit For
            Next cell
    Next
    
        ActiveCell.PasteSpecial xlValues
        
Application.ScreenUpdating = True
Exit Sub


M:
MsgBox "No such sheet as  " & ans & " exist"
Application.ScreenUpdating = True


End Sub

With the above, I unmerged cell M54 and moved the title "Average / Totals" into cell N54. This is required for the macro to function correctly. There must not be anything entered in the M COLUMN in or below M54.
 
Thanks very much for having a look at this and providing the code, it's very much appreciated.
I have unmerged M54 and have cut and pasted it into N54. I am getting an error when trying to run the macro, the first line of the code is in red. Am I doing doing something wrong? See the snippet. Thanks again.
 

Attachments

  • Capture.JPG
    Capture.JPG
    82.1 KB · Views: 8
My apologies ... that was my fault ... an oversight.

Code:
Sub CopyOwnTab()

Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim ws As Worksheet
Dim ans As String




Set ws = ActiveSheet




On Error GoTo M
 
This is working perfectly.

Thanks so much for taking the time out to help.
:D
 
You are welcome. Glad to help.
 
Back
Top