【问题标题】:Random numbers and characters with no duplicated using excel使用excel没有重复的随机数字和字符
【发布时间】:2021-04-21 18:37:24
【问题描述】:

请任何人都可以帮助我, 我需要像这样(“A6”)用一个数字和一个字符填充单元格 在垂直列中没有重复,

如果你能给我一个 vba 代码或任何其他的东西来做, 谢谢。。

【问题讨论】:

  • 欢迎来到 Stack Overflow。请注意,由于这不是免费的代码编写服务,因此您有必要展示到目前为止您尝试过的内容以及遇到的问题或错误(通过展示您的代码),或者至少展示您的研究内容和您所做的努力制成。否则,它只是要求我们为您完成所有工作。阅读How to Ask 可能会帮助您改进您的问题。

标签: excel vba duplicates row


【解决方案1】:

只需遍历任意行,并生成随机数和随机字符,如下所示:

For i = 1 To row_limit
    For j = 1 To column_limit
        try_cell = CStr(Int((upperbound - lowerbound + 1) * Rnd + lowerbound)) & Random_char() 'generate random cell address
        Do While True 'check if current 'cell' generated in row
            before = try_cell
            For w = 1 To j
                If try_cell = shee1.Cells(i, w) Then 'means it already exits and need to generate again
                    try_cell = CStr(Int((upperbound - lowerbound + 1) * Rnd + lowerbound)) & Random_char()
                    Exit For
                End If
            Next
            If before = try_cell Then 'only if not in row, move on
                sheet1.Cells(i, j) = try_cell
                Exit Do
            End If
        Loop
    Next
Next

你可以在这里查看如何生成随机字符Random String & Number Generation access vba

【讨论】:

  • 谢谢你的回答,但我不明白
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-05
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多