如何随机化excel单元格中的值?

时间:2018-05-04 17:15:45

标签: excel cell formula

我正在尝试为每个细胞随机化一个细胞值。我想把字母“tyot”保留在单词的前面,然后随机化后面的7个字母,我用这个公式做了:

=CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90))& CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99) 

并且在使用类似=A1&""&B1之类的公式连接两个单元格后,我得到了我想要的结果,它看起来像tyotXKWAE73。现在,下一步是我无法弄清楚的,即随机化最后六个字母"tXKWAE73"并将"tyot"始终放在前面。关于如何做最后一步的任何想法?

1 个答案:

答案 0 :(得分:0)

在标准模块中输入以下功能:

sudo chown -R $(whoami) /var/deploy/kids/web_head/shared/bundle/ruby/2.3.0/gems/*

然后在 B1 中输入:

Public Function Shuffle(s As String) As String
    Dim ary(1 To 7) As String, ndex(1 To 7)
    For i = 1 To 7
        ary(i) = Mid(s, i, 1)
        ndex(i) = i
    Next i
    Call Shuffle2(ndex)
    Shuffle = ""
    For i = 1 To 7
        Shuffle = Shuffle & ary(ndex(i))
    Next i
End Function

Public Sub Shuffle2(InOut() As Variant)
    Dim i As Long, J As Long
    Dim tempF As Double, Temp As Variant

    Hi = UBound(InOut)
    Low = LBound(InOut)
    ReDim Helper(Low To Hi) As Double
    Randomize

    For i = Low To Hi
        Helper(i) = Rnd
    Next i

    J = (Hi - Low + 1) \ 2
    Do While J > 0
        For i = Low To Hi - J
          If Helper(i) > Helper(i + J) Then
            tempF = Helper(i)
            Helper(i) = Helper(i + J)
            Helper(i + J) = tempF
            Temp = InOut(i)
            InOut(i) = InOut(i + J)
            InOut(i + J) = Temp
          End If
        Next i
        For i = Hi - J To Low Step -1
          If Helper(i) > Helper(i + J) Then
            tempF = Helper(i)
            Helper(i) = Helper(i + J)
            Helper(i + J) = tempF
            Temp = InOut(i)
            InOut(i) = InOut(i + J)
            InOut(i + J) = Temp
          End If
        Next i
        J = J \ 2
    Loop
End Sub

B2 中输入:

=CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90))& CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99)

并向下复制:

enter image description here

B 列中的每个条目都是"随机化"带有固定前缀的 B1