theteague
theteague

Reputation: 413

Need VBA code to click button that moves contents from one cell to another

I have a bundle of data on my worksheet that I update every day. Cell B9 displays the results of a formula that is calculated using this bundle of data. I want to add a button to my Excel worksheet that when clicked will take the value displayed in cell B9 and put it in cell P2 on the same worksheet. Tomorrow, I'll come in and update the bundle of data, which updates the value displayed in B9, and I'll click the button again which will move the value displayed in B9 to the next available cell in column P. I'll repeat this process every day to build trended data. My VBA skills are very dim... I can find VBA code to move data from one place to another. I can find VBA code to 'find the next available cell' but I don't know an eloquent way to marry the 2 scripts together to achieve my desired outcome.

Upvotes: 0

Views: 912

Answers (1)

Damian
Damian

Reputation: 5174

Here is your Code:

Sub ExportData()

    Dim LastRow As Long
    LastRow = ActiveSheet.Range("P1000000").End(xlUp).Row + 1 'first available row

    ActiveSheet.Range("P" & LastRow) = ActiveSheet.Range("B9") 'value from P LastRow = Value from Cell B9

End Sub

Upvotes: 3

Related Questions