Loop through the cell which have value and paste the same value to same cell by command button.

  • Hi, Hope everybody is fine.

    I am using a code to input the same data to the same cell

    Private Sub CommandButton1_Click()
        Dim names As Range
        Set names = Range("J10:J15")
        Dim cell As Range
        For Each cell In names
            cell.Value = cell.Value
        Next cell
    End Sub

    But the problem is I need to expand the range up to J10 to J1000.

    When I did the code takes an unexpectedly long time though not all the calls in J10 to J1000 had value.

    So can anyone help me how to modify the code only for the cell having value and to work faster.

    Thanks and Best Regards.

  • Not sure what you are trying to achieve with that code, but this will give the same result without looping

    Private Sub CommandButton1_Click()
        Range("J10:J1000").Value = Range("J10:J1000").Value
    End Sub

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Thank You KjBox,

    Very pleased that you are here. Sometimes simple things are very hard to achieve.

    Actually, On selection, in between Range J10:J1000 is not showing but if I use the above code then it works but the looping through the range takes a long time.

    Now the issue solve. Thank you Kjbox.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!