Share via

Random Name Generator

Anonymous
2025-03-18T21:43:50+00:00

Hi all, apologies if this has been asked previously.

I wish to randomly select a name from a large list (the same name appears more than once) and remove all occurrences of that name once it is selected.

Any help will be appreciated.

Thank you

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2025-03-25T06:20:02+00:00

Is there any update on it? You may also give feedback on it.

Feel free to come back if you need any help about Excel.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2025-03-19T22:04:45+00:00

    Thank you very much.

    Will give this a try.

    Appreciate your help.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2025-03-19T00:21:24+00:00

    Try this macro

    Sub RemoveRandomNameAndLog()

    Dim ws As Worksheet
    
    Dim lastRow As Long
    
    Dim rng As Range
    
    Dim randomIndex As Long
    
    Dim selectedName As String
    
    Dim logRow As Long
    
    ' Set the worksheet
    
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    
    ' Find the last row with data in column A
    
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' Check if there are any names in column A
    
    If lastRow<1 Then
    
        MsgBox "No names found in column A."
    
        Exit Sub
    
    End If
    
    ' Set the range of names in column A
    
    Set rng = ws.Range("A1:A" & lastRow)
    
    ' Generate a random index
    
    Randomize
    
    randomIndex = Int((rng.Rows.Count) \* Rnd + 1)
    
    ' Get the randomly selected name
    
    selectedName = rng.Cells(randomIndex, 1).Value
    
    ' Find the next empty row in column C
    
    logRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row + 1
    
    ' Log the removed name in column C
    
    ws.Cells(logRow, 3).Value = selectedName
    
    ' Remove all occurrences of the selected name
    
    For i = lastRow To 1 Step -1
    
        If ws.Cells(i, 1).Value = selectedName Then
    
            ws.Cells(i, 1).Delete
    
        End If
    
    Next i
    

    End Sub

    Was this answer helpful?

    0 comments No comments