Option Explicit
Sub AcronymRand(N, AcroLen, AcroLib, AcroName)
Static Count As Long
Dim I As Integer
Dim J As Long
Dim LR As Long
Dim ProcTitle As String
Dim strBuffer As String
Dim strName As String
Dim xlSheet As Worksheet
ProcTitle = "Acronym Engine"
If AcroLen < 1 Or AcroLib = "" Or AcroName = "" Then
MsgBox "one or more arguements passed to AcronymRand" & vbCrLf & _
"are not valid" & vbCrLf & _
"AcroLen = " & vbTab & AcroLen & vbCrLf & _
"AcroLib = " & vbTab & AcroLib & vbCrLf & _
"AcroName = " & vbTab & AcroName, vbOKOnly + vbCritical, ProcTitle
Exit Sub
End If
If Count = 0 Then Randomize
Set xlSheet = Worksheets(AcroLib)
For J = 1 To N
strName = ""
Count = Count + 1
For I = 1 To AcroLen
With xlSheet.Range(xlSheet.Cells(1, I), xlSheet.Cells(1000, I))
LR = .Cells.Find("*", .Cells(1), xlFormulas, _
xlWhole, xlByRows, xlPrevious).Row
strName = strName & xlSheet.Cells(RandRange(1, LR), I).Text & " "
End With
Next I
If N = 1 Then
MsgBox AcroName & " # " & Count & " is " & vbCrLf & strName, _
vbOKOnly + vbInformation, ProcTitle
GoTo CleanUp
End If
strBuffer = strBuffer & Count & vbTab & strName & vbCrLf
Next J
MsgBox vbTab & AcroName & vbCrLf & vbCrLf & strBuffer, _
vbOKOnly + vbInformation, ProcTitle
CleanUp:
Set xlSheet = Nothing
End Sub
Sub AcronymCombos(AcroLen, AcroLib)
Dim Combos As Long
Dim I As Long
Dim ProcTitle As String
Dim strBuffer As String
Dim xlLastRow As Long
Dim xlSheet As Worksheet
ProcTitle = "Acronym Engine"
If AcroLen < 1 Or AcroLib = "" Then
MsgBox "one or more arguements passed to AcronymCombos" & vbCrLf & _
"are not valid" & vbCrLf & _
"AcroLen = " & vbTab & AcroLen & vbCrLf & _
"AcroLib = " & vbTab & AcroLib & vbCrLf, vbOKOnly + vbCritical, ProcTitle
Exit Sub
End If
Set xlSheet = Worksheets(AcroLib)
Combos = 1
For I = 1 To AcroLen
With xlSheet.Range(xlSheet.Cells(1, I), xlSheet.Cells(1000, I))
xlLastRow = .Cells.Find("*", .Cells(1), xlFormulas, _
xlWhole, xlByRows, xlPrevious).Row
End With
Combos = Combos * xlLastRow
strBuffer = strBuffer & "# names in col " & I & " =" & vbTab & _
xlLastRow & vbCrLf
Next I
MsgBox "AcronymCombos" & vbCrLf & vbCrLf & strBuffer & vbCrLf & _
"# unique combinations = " & Combos, vbInformation
CleanUp:
Set xlSheet = Nothing
End Sub
Sub AcronymLibScan(AcroLen, AcroLib)
Dim Dups As Long
Dim I As Long
Dim J As Long
Dim K As Long
Dim ProcTitle As String
Dim strBuffer As String
Dim xlLastRow As Long
Dim xlSheet As Worksheet
ProcTitle = "Acronym Engine"
If AcroLen < 1 Or AcroLib = "" Then
MsgBox "one or more arguements passed to AcronymLibScan" & vbCrLf & _
"are not valid" & vbCrLf & _
"AcroLen = " & vbTab & AcroLen & vbCrLf & _
"AcroLib = " & vbTab & AcroLib & vbCrLf, vbOKOnly + vbCritical, ProcTitle
Exit Sub
End If
Set xlSheet = Worksheets(AcroLib)
For I = 1 To AcroLen
With xlSheet.Range(xlSheet.Cells(1, I), xlSheet.Cells(1000, I))
xlLastRow = .Cells.Find("*", .Cells(1), xlFormulas, _
xlWhole, xlByRows, xlPrevious).Row
End With
For J = 1 To xlLastRow - 1
For K = J + 1 To xlLastRow
If xlSheet.Cells(J, I) = xlSheet.Cells(K, I) Then
Dups = Dups + 1
strBuffer = strBuffer & I & vbTab & J & vbTab & K & vbTab & _
xlSheet.Cells(J, I) & vbCrLf
End If
Next K
Next J
Next I
If Dups = 0 Then
MsgBox "Scan of " & AcroLib & " complete. No dups found", vbInformation
Else
MsgBox "Scan of " & AcroLib & " complete. " & Dups & " dups found" & _
vbCrLf & vbCrLf & _
"Col" & vbTab & "Row1" & vbTab & "Row2" & vbTab & "Text" & vbCrLf & _
strBuffer, vbInformation
End If
CleanUp:
Set xlSheet = Nothing
End Sub
Function RandRange(I, J) As Long
RandRange = I + Rnd() * (J - I)
If RandRange < I Then RandRange = I
If RandRange > J Then RandRange = J
End Function
|