Search code examples
excelvbacopy

Copy cell value with newest addition first, oldest downwards


enter image description here

I'm working on an overtime Excel worksheet. Now I'm stuck with this problem.

I want to copy the cell value from the total hours/or minutes in the right column with the name. But is there a way to have the newest date/overtime-hours to be the top, and when you click the button again, the newest addition stays on top and the older hours go down and down and down?

While checking if there is data in that cell? If there is no data, it should stay on top after the first hours/click.

Below is what I would want:

enter image description here

I've tried selecting, cutting and pasting but it keeps overwriting the topmost cell ...


Solution

  • If there is data in K11, Insert will shift cells down. Then update K11 with new data.

        With Range("K11")
            If Len(Trim(.Value)) > 0 Then .Insert shift:=xlShiftDown
            .Value = "|" & [B15] & "|" & [D15] & " uur " & [D15] & "min"
        End With