Mark 8 random With "X"

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Using Excel 2010
Hello,

I need VBA which can mark 8 random with “X” in column D from data column C

Data sheet...
Excel Question.xlsm
ABCDEF
1
2
3Mixed Mark
4Num & TextRandom
5Total 148 With X
6A
71X
8DX
95
1010X
1112X
12F
1315X
14A
15DX
16F
1722X
1827
1932X
20
Sheet1



Regards,
Moti
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You just need to mark first 8 numbers with "X"?
 
Upvote 0
No, I need 8 out of 14 to be marked numbers or text randomly are in the column C
 
Upvote 0
Hi Moti,
here is my attempt, change the sheet name and destination range in the code if necessary

VBA Code:
Sub Insert8RandomX()
'https://www.mrexcel.com/board/threads/mark-8-random-with-x.1265256/

    Dim rng As Range, cel As Range
    Dim i As Integer, intPos() As Integer
    Dim intRandom As Integer, temp As Integer       
    
    Set rng = Sheets("Sheet1").Range("D6:D19") 'ADAPT sheet name and range if needed
    rng.ClearContents   
    
    ReDim intPos(1 To 14)
    For i = 1 To 14
        intPos(i) = i
    Next i   
    
    For i = 1 To 14
        intRandom = Int((14 - i + 1) * Rnd + i)
        temp = intPos(i)
        intPos(i) = intPos(intRandom)
        intPos(intRandom) = temp
    Next i   
    
    For i = 1 To 8
        rng.Cells(intPos(i)).Value = "X"
    Next i
      
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,223,952
Messages
6,175,594
Members
452,655
Latest member
goranzoric

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top