You got a two column range there. Assuming you got the personID in A, and the name in B, maybe you want to get Rnd * rng.Rows.count to get a row number (rather than a cell number), and then from that row get the value of the second cell. That way, you get the column B that belongs to the random cell in column A. – WebJun 21, 2024 · You could use RandBetween worksheet function. It will generate a number between 1 and 10 and use that to select the cell within the range A1:A10. The example …
VBA Selecting Range How to Select a Range of Cells in Excel …
WebFor the lower value, we use the number 1, and for the upper value we use the ROWS function to get count the total rows in the table or list: = RANDBETWEEN (1, ROWS ( data)) RANDBETWEEN will return a … WebAug 31, 2024 · Sub DelThirty () Dim rng As Range Dim i As Long, x As Long, y As Long Set rng = Selection On Error GoTo ErrHandler Application.Calculation = xlCalculationManual Application.ScreenUpdating = False For i = 1 To Int (rng.Cells.Count * 0.3) retry: x = WorksheetFunction.RandBetween (1, rng.Rows.Count) y = … engineering companies in new jersey
Working with Cells and Ranges in Excel VBA (Select, Copy
WebJan 26, 2016 · It’s as easy as selecting the range. See below. Example. Let’s say you have data contained in a range of cells between A1 and D200. Let’s say this range contains a set of names and you want to randomly select one. You would use the following formula in Excel. =pwrRANDFROMRANGE(A1:D200) If your data is contained in a single column. … WebThe following code will populate a given range with a random number between 0 and 1000: Sub Randomise_Range (Cell_Range As Range) ' Will randomise each cell in Range … WebSep 29, 2024 · Code below can do that only for column "G". How to change code for my range? Sub Testa () Dim LR As Long, cell As Range, rng As Range With Sheets ("Sheet1") LR = .Range ("G" & Rows.Count).End (xlUp).Row For Each cell In .Range ("G2:G" & LR) If cell.Value <> "" Then If rng Is Nothing Then Set rng = cell Else Set rng = Union (rng, … dreamcourts