Friday, April 10, 2026

select random range cell copy in vba excel - copy random cell in excel macro

 Sub Macro3()

    Dim Rng As Range

    Dim randomIdx As Long

   

    ' Set your target range

    Set Rng = Range("K3:K4591")


    ' Initialize the random number generator

    Randomize


    ' Generate a random index between 1 and the total number of cells

    randomIdx = Int(Rnd * Rng.Cells.Count) + 1

    

    ' Select the cell at that index

    Rng.Cells(randomIdx).Select

     Selection.Copy

End Sub


No comments:

Post a Comment