PC Review


Reply
Thread Tools Rate Thread

Creating Compiled Word Lists

 
 
Rob
Guest
Posts: n/a
 
      27th Jun 2009

I was just wondering if it would be possible to have a macro take the values
of a set of cells/ranges (say A1 thru A5) and have Column C Filled with as
many random combinations of those values strung together in say.... 200
permutations?

Generally I'm thinking of applying this to generating random Hex or Binary
strings or just Gibberish Sentences.

Well, if it's possible would you please help.


Thanks In Advance,
Rob
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      27th Jun 2009

Hi Rob,

With the following code you can enter words in column A for as many cells as
you like starting from cell A1.

The code first asks how many words to include in each cell of the output.
(Default is 6)
It then asks how many cells of output required. (Default is 200)

It does not repeat any random string.

If the code has difficulty creating the number of unique random strings due
to either too few words or too many cells of output then the processing
aborts.

Because the code uses the RANDBETWEEN function you need the analaysis tool
pak addin loaded. This is a standard Excel feature. See Addins in help to
find out how to load it. (If you have a problem with this then let me know
what version of xl you are using.)


Sub RandomFromList()

Dim rngList As Range
Dim lngNumbInCell As Long
Dim lngNumbOfCells As Long
Dim lngCellLast As Long
Dim lngCountDuplicates As Long
Dim strTemp As String
Dim i As Long
Dim j As Long

lngNumbInCell = Application.InputBox _
(prompt:="Enter the number of words in each cell", _
Title:="Number of words in each cell", _
Default:=6, Type:=1)

lngNumbOfCells = Application.InputBox _
(prompt:="Enter the number of cells required", _
Title:="Number of cells to fill", _
Default:=200, Type:=1)

'Edit the sheet name to match required sheet
With Sheets("Sheet1")
Set rngList = .Range(.Cells(1, 1), _
Cells(.Rows.Count, 1).End(xlUp))

lngCellLast = rngList.Rows.Count

For i = 1 To lngNumbOfCells
lngCountDuplicates = 0

CreateRandStr:
strTemp = ""
For j = 1 To lngNumbInCell
strTemp = strTemp & " " & _
rngList.Cells(WorksheetFunction _
.RandBetween(1, lngCellLast))
Next j

'Test for existing random string
If WorksheetFunction.CountIf(.Columns("C:C"), _
"=" & strTemp) = 0 Then

'Add string if not yet existing
.Cells(i, "C") = strTemp
Else
lngCountDuplicates = lngCountDuplicates + 1

'Abort processing if cannot create required
'number of random strings
If lngCountDuplicates > 10 Then
MsgBox "insufficient options to create " _
& lngNumbOfCells & " random strings" _
& vbCrLf & "Processing will terminate"
Exit Sub
End If

GoTo CreateRandStr
End If
Next i
End With
End Sub

--
Regards,

OssieMac


 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      27th Jun 2009

Holy.......!! That's perfect! Thanks Very Much!



"OssieMac" wrote:

> Hi Rob,
>
> With the following code you can enter words in column A for as many cells as
> you like starting from cell A1.
>
> The code first asks how many words to include in each cell of the output.
> (Default is 6)
> It then asks how many cells of output required. (Default is 200)
>
> It does not repeat any random string.
>
> If the code has difficulty creating the number of unique random strings due
> to either too few words or too many cells of output then the processing
> aborts.
>
> Because the code uses the RANDBETWEEN function you need the analaysis tool
> pak addin loaded. This is a standard Excel feature. See Addins in help to
> find out how to load it. (If you have a problem with this then let me know
> what version of xl you are using.)
>
>
> Sub RandomFromList()
>
> Dim rngList As Range
> Dim lngNumbInCell As Long
> Dim lngNumbOfCells As Long
> Dim lngCellLast As Long
> Dim lngCountDuplicates As Long
> Dim strTemp As String
> Dim i As Long
> Dim j As Long
>
> lngNumbInCell = Application.InputBox _
> (prompt:="Enter the number of words in each cell", _
> Title:="Number of words in each cell", _
> Default:=6, Type:=1)
>
> lngNumbOfCells = Application.InputBox _
> (prompt:="Enter the number of cells required", _
> Title:="Number of cells to fill", _
> Default:=200, Type:=1)
>
> 'Edit the sheet name to match required sheet
> With Sheets("Sheet1")
> Set rngList = .Range(.Cells(1, 1), _
> Cells(.Rows.Count, 1).End(xlUp))
>
> lngCellLast = rngList.Rows.Count
>
> For i = 1 To lngNumbOfCells
> lngCountDuplicates = 0
>
> CreateRandStr:
> strTemp = ""
> For j = 1 To lngNumbInCell
> strTemp = strTemp & " " & _
> rngList.Cells(WorksheetFunction _
> .RandBetween(1, lngCellLast))
> Next j
>
> 'Test for existing random string
> If WorksheetFunction.CountIf(.Columns("C:C"), _
> "=" & strTemp) = 0 Then
>
> 'Add string if not yet existing
> .Cells(i, "C") = strTemp
> Else
> lngCountDuplicates = lngCountDuplicates + 1
>
> 'Abort processing if cannot create required
> 'number of random strings
> If lngCountDuplicates > 10 Then
> MsgBox "insufficient options to create " _
> & lngNumbOfCells & " random strings" _
> & vbCrLf & "Processing will terminate"
> Exit Sub
> End If
>
> GoTo CreateRandStr
> End If
> Next i
> End With
> End Sub
>
> --
> Regards,
>
> OssieMac
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating custom numbering/lists in Word 2007 Jess Microsoft Word New Users 0 13th May 2009 05:54 AM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander Microsoft ASP .NET 5 5th Mar 2008 04:34 PM
Creating lists as I did in Word 97 =?Utf-8?B?S2FyZW4gQg==?= Microsoft Word New Users 6 11th Feb 2006 06:13 AM
need to send group addresses to Bcc , compiled in Word 2003.sent . =?Utf-8?B?bWFnZ2ll?= Microsoft Word New Users 0 31st Dec 2004 06:51 AM
Help Creating Lists ams228 Microsoft Excel Misc 3 11th May 2004 09:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:59 AM.