0

I have this simple vba,

Private Sub CommandButton7_Click()
Range ("F1:F100").Value=Time

End Sub

As you already know, this will insert the current time in cells from F1 to F100(all at once) whenever I click the button once.

However, I want to insert time in each cells for each click. If I click the button first time, only f1 should be filled in. The second click should fill in f2 only because the previous cell is empty and so on and so forth.

I am not sure if it should be done in loop but I was unable to find references. I am trying to find a simpler code to achieve this.

  • 1
    Does this answer your question? [Better way to find last used row](https://stackoverflow.com/questions/38882321/better-way-to-find-last-used-row) – Warcupine Nov 10 '22 at 19:13
  • No, i was looking for something like this-Range(Cell Range increment by 1)= Time – Habeeb E Sadeed Nov 10 '22 at 19:19
  • 1
    If you are entering one per click then finding the last row does increment it. – Warcupine Nov 10 '22 at 19:28
  • 1
    But, the above suggestion pointed in that direction... I mean: `Dim timeCell as Range` `Set timeCell = Range("F" & rows.count).End(xlUp).Offset(1)` `timeCell.value = time` – FaneDuru Nov 10 '22 at 19:30

1 Answers1

0

Thanks commentators for your assistance.I just put the answer below in case any one needs it. The code below served my objective.

Once a cell is filled in upon clicking, you can directly go to the next cell and fill in the cell value upon clicking the button again,

    Dim timeCell as Range 
    Set timeCell = Range("F" & rows.count).End(xlUp).Offset(1)
    timeCell.value = time