Random fill 1X2

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
I need a VBA or a formula, which can fill random 1X2 in the cells C6:E19

Example....


Book1
ABCDEFG
1
2
31X2
4
511
621
732
84X
951
106X
1172
128X
139X
14101
1511X
16122
1713X
18141
19
20
21
22
Sheet3


Thank you in advance

Regards,
Kishan
 
How about:

VBA Code:
Sub f1x2()
  Dim r As Range, c As Range, n As Long
  Set r = Range("B6:B19")
  r.Offset(, 1).Resize(r.Rows.Count, 3).ClearContents
  Randomize
  For Each c In r
    n = Int(3 * Rnd + 1)
    c.Offset(, n) = Choose(n, "1", "x", "2")
  Next
End Sub
DanteAmor, it worked fine! thank you very much
kind Regards,
Kishan
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Silly mistake on my part... I forgot an Int function call. Here is the revised code...
VBA Code:
Sub Random1X2()
  Dim R As Long, RndNum As Long
  Randomize
  Range("C6:E19").Clear
  For R = 6 To 19
    RndNum = Int(3 * Rnd + 1)
    Cells(R, "B").Offset(, RndNum) = Mid("1X2", RndNum, 1)
  Next
End Sub
Rick, thank you so much it worked well! Generating all 14 random perfectly
kind Regards,
Kishan
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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