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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
why I do not see the MrExcelHtml shot I posted ? Can anybody help please, also noticed that all my previous threads has disappeared example shots
 
Upvote 0
 
Upvote 0
why I do not see the MrExcelHtml shot I posted ? Can anybody help please, also noticed that all my previous threads has disappeared example shots
The forum software is new.... did you use the "Upload image" button at the bottom of the message window to post your picture?
 
Upvote 0
well I do not know is it correct? it look to me all complicate
 

Attachments

  • Random 1X2.png
    Random 1X2.png
    8.6 KB · Views: 23
Upvote 0
Give this macro a try...
VBA Code:
Sub Random1X2()
  Dim R As Long, RndNum As Long
  Randomize
  For R = 6 To 19
    RndNum = 3 * Rnd + 1
    Cells(R, "B").Offset(, RndNum) = Mid("1X2", RndNum, 1)
  Next
End Sub
 
Upvote 0
Hi Rick, thank you for the code it is generating but there are missing some rows it is creating every time different numbers of row 8, 10, 11 an so it must generate 14 please can you take a look
Kind Regards
Kishan
 
Upvote 0
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
 
Upvote 0
Hi Rick, thank you for the code it is generating but there are missing some rows it is creating every time different numbers of row 8, 10, 11 an so it must generate 14 please can you take a look
Kind Regards
Kishan

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
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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