dポイントプレゼントキャンペーン実施中!

マスターとプレイヤーで分けており、マスターとプレイヤーにそれぞれにしりとりができるプロシージャを入力したいのですがあまりわからいので簡単なやり方でプロシージャを回答に入力して教えてください。大変だと思いますがよろしくお願いします。

A 回答 (1件)

添付の図のとおりシートを作ってください。

その後、次のマクロを実行するとC2以下にしりとりの結果が表示されます。
シートは、A列がしりとりに使うワード。C1セルは最初のお題となっています。

Sub sample()
Dim Word As Range
Dim i As Long
Set Word = Range("C1")
Do Until Word.Value = ""
Word.Offset(1).Value = Siritori(Word.Value)
Set Word = Word.Offset(1)
Loop
End Sub

Function Siritori(Kotoba As String) As String
Dim c As Range
Dim firstAddress As String

With Worksheets("Sheet1").Range("A:A")
Set c = .Find(Right(Kotoba, 1) & "*", LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
If c.Offset(0, 1).Value = "" Then
c.Offset(0, 1).Value = "済"
Siritori = c.Value
Exit Do
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Function
「ExcelVBAでしりとりのやり方を教え」の回答画像1
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!