LoginSignup
0
0

More than 1 year has passed since last update.

アルファベットの連続データを取得するVBScript

Last updated at Posted at 2021-12-19

A、B、C、D・・AA、AB・・BA、BB・・と続くデータ(要するに Excel の列名)をテキストで取り出す VBScript

GetAlphabetSequence.vbs
Dim val
val = CLng(GetInput("連続データの個数を入力してください"))
CreateObject("WScript.Shell").Exec("clip").StdIn.Write GetAlphabetSequence(val)
Msgbox "アルファベットの連続データを " & val & " 個コピーしました。"
Function GetAlphabetSequence(ByVal seq_length)

    Dim i, r, n, str, alphabetSequence

    For i = 1 To seq_length
        n = i
        str = ""

        Do While n > 26
            r = n Mod 26: If r = 0 Then r = 26
            n = n \ 26: If r = 26 Then n = n - 1
            str = Chr(r + 64) & str
        Loop

        If n <> 0 Then str = Chr(n + 64) & str
        alphabetSequence = alphabetSequence + str + vbCrLf
    Next

    GetAlphabetSequence = alphabetSequence

End Function
'// InputBox の入力値を返す
Function GetInput(ByVal msg)
    Dim val
    val = InputBox(msg)
    If IsEmpty(val) Then MsgBox "キャンセルされました。": WScript.Quit
    If val = "" Then MsgBox "何も入力されていません。": WScript.Quit
    GetInput = val
End Function
0
0
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
0
0