0

I have 2 forms on the same worksheet. The first allows users to input contracted hours / start dates to determine their annual leave entitlement. This is a formula and the figures are in cells I20, J20 and K20.

When the User clicks a command button, these figures are to be copied over to a Running Total form on the same worksheet, to cells P17, Q17 and R17. If the User then changes their contracted hours on the first form and clicks the command button again, then the new figures are to be copied over to cells P18, Q18 and R18. This step can be repeated a number of times (the last row for copying the data is P22, Q22, R22).

This Running Total form has on its very last row a formula that sums the totals that have been put on the form.

I'm new to VBA but have managed to create the following code that copies the figures into P17, Q17 and R17 - but I'm not sure how to get the next figures into the row below. I feel this should be a straight forward thing to do but I am struggling a little with this. Any help would be appreciated.

Sub CopyRange()

'Value Paste Cells

Worksheets("Calculator").Activate

Range("P15").End(xlDown).Offset(1, 0).Select

ActiveCell.Value = Range("I20")
ActiveCell.Offset(0, 1).Value = Range("J20")
ActiveCell.Offset(0, 2).Value = Range("K20")

  Range("P23").End(xlUp).Offset(1, 0).Select

End Sub

Initially I get the figures showing in the Running Total Form copied into P17, Q17 and R17 after clicking the command button. It then shows active cell to be P18. If I then change the figures on the first form and click the command button again - nothing happens.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Ejike
  • 1
  • 1
  • 1
    (One tip is to [not use `.Select`](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba)) – BruceWayne Feb 08 '19 at 18:12

1 Answers1

0

Without seeing your sheet, it's hard to know exactly where to place and End(xlUp) or End(xlDown), but this should get you started in a good way. Tweak as neeeded.

With Worksheets("Calculator")

    .Range("P23").End(xlUp).Offset(1, 0).Resize(1,3).value = .Range("I20:K20").Value

End With
Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72