Home > Back-end >  How to select a range that moves
How to select a range that moves

Time:11-08

I am new to VBA and need some help. I am setting up a file in which a user will input four rows of data and then press a command button which should be able to add only the last for rows that have been entered. how do I set it up so that the calculation will only add the most recent four rows of data?

Thanks in advance, Shane.

CodePudding user response:

Private Sub CommandButton1_Click()
Dim x
x = Range("a1").End(xlDown).Value   Range("a1").End(xlDown).Offset(-1, 0).Value   Range("a1").End(xlDown).Offset(-2, 0).Value   Range("a1").End(xlDown).Offset(-3, 0).Value
Range("b3").Value = x
End Sub

CodePudding user response:

Private Sub CommandButton1_Click()
Dim x
x = Range("a1").End(xlDown).Value   Range("a1").End(xlDown).Offset(-1, 0).Value   Range("a1").End(xlDown).Offset(-2, 0).Value   Range("a1").End(xlDown).Offset(-3, 0).Value
Range("b3").Value = x
End Sub
  • Related