1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

選択範囲のセルに8文字のランダム文字列を出力するExcelマクロ

Posted at

' ランダムな文字列生成
Public Function MakePassword(Optional intLength As Integer = 8, Optional boolIncUpper As Boolean = False, Optional boolIncSign As Boolean = False)

    Dim strPass As String
    Dim strLower As String
    Dim strUpper As String
    Dim strNumber As String
    Dim strSign As String
    Dim strChars As String
    Dim intMax As Integer
    Dim i As Integer
    
    strLower = "qwertyuiopasdfghjklzxcvbnm"
    strUpper = "QWERTYUIOPASDFGHJKLZXCVBNM"
    strNumber = "123456789"
    strSign = "-^@[;:],./!""#$%&'()=~|`{+*}<>?_"

    strChars = strLower & strNumber & strUpper

    If boolIncUpper = True Then
    
        strChars = strChars & strUpper
    
    End If
    
    If boolIncSign = True Then
    
        strChars = strChars & strSign
        
    End If

    intMax = Len(strChars)
    
    For i = 1 To intLength
    
        strPass = Mid(strChars, Int((intMax - 1 + 1) * Rnd + 1), 1) & strPass
    
    Next i

    MakePassword = strPass

End Function

Sub makePassworMain()
    
    Dim selectionCell As Range

    For Each selectionCell In Selection
        selectionCell = MakePassword
    Next

End Sub

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?