Macro to put data in last row in columns

Cantrecallmyusername

Board Regular
Joined
May 24, 2021
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi there,

My spreadsheet has a table where I want the current date to inputted into starting at cell D18 and copy the cell value in F10 and paste this value into E18 when I run a macro. The next time I run the macro I want the data to move one row down and do the same thing each time the macro is ran.

So in E18 the date would be updated and the value would be copied from F10 once again and pasted into E19.
I would like this to be able to handle multiple runs of the macro.

I have used this -
last_cell = Cells.Find("*", SearchDirection:=xlPrevious) .Row
though cant seem to figure out how to include this in the above scenarios.

Thanks in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You really did not give a lot of information about your table. This assumes that your table name is Table1 and that the first cell of the table is Cell D18. If that is not the case you will have make adjustments to the lines where indicated. The code is really intended as a jumping off point for you to get what you need.

The following is a good site for understanding tables, you may want to look at it...


VBA Code:
Sub FillTable()

    Dim tbl As ListObject
    
    Set tbl = ActiveSheet.ListObjects("Table1")
    If Range("D18") = "" Then
        Range("D18") = Date
        Range("E18") = Range("F10")
        Exit Sub
    End If
    tbl.ListRows.Add Alwaysinsert:=True
    tbl.DataBodyRange(tbl.ListRows.Count, 1) = Date             'Adjust this line
    tbl.DataBodyRange(tbl.ListRows.Count, 2) = Range("F10")      'Adjust this line
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top