0

Okay I'm needing some help with excel i'm new to it. I have a spreadsheet that adds all these value together and puts them in cell M3. However this is a daily spreadsheet I will be using so I want to add a button that will run a macro to copy the value from M3 to N7 the first time I click it. But then the next time I click it I want it to copy the value from M3 to N8 and so on up to N37 for a months time.

I have been trying to get this done for awhile now and can't seem to find anything to help me thought I would ask here and also hoping someone would explain the code a bit for me so I can better understand it. I got the button added already so no need to tell me how to do that.

3 Answers3

2

This does what you want.

When you run VBa, there is no undo, so take a backup of your file first and play with a copy!!

Please note the comments in the code, this is things you will need to update

I have also assumed you're not using worksheet2 so this code uses it!

Option Explicit
Sub SaveAsNewRow()

Dim sourceData As String
sourceData = "A1"                          'the column and row from where you want to copy FROM

Dim destinationData As String
destinationData = "B"                          'the column from where you want to copy TO

Dim newRow As Integer
newRow = 1
Do While (Range(destinationData & newRow).Value <> "")
    newRow = newRow + 1
Loop

Worksheets("sheet1").Range("B" & newRow).Value = Worksheets("sheet1").Range(sourceData).Value

End Sub

How do I add VBA in MS Office?

Dave
  • 25,513
2

By using the function Tools->Macro->Record New Macro..., you can do all your operations like before (with Keyboard and Mouse) and after that (stop record) you can take a look at the generated macro-code.
This can help in many cases.

If you have any special problems, please post your code.

Ben
  • 359
2

Put any Shape or AutoShape on the worksheet and assign this macro to it:

Sub SaveResults()
    Dim N As Long
    If Range("N7").Value = "" Then
        N = 7
    Else
        N = Cells(Rows.Count, "N").End(xlUp).Row + 1
    End If
    Cells(N, "N").Value = Range("M3").Value
End Sub