Dim wsSource As <REDACTED> wsDest As <REDACTED> classArray As <REDACTED> i As Integer
Dim j As Long
Dim c As Range
Dim firstAddress As String
Set wsSource = ThisWorkbook.Sheets("先生別")
Set wsDest = ThisWorkbook.Sheets.Add
wsDest.Name = "クラス別"
classArray = <REDACTED>, 12, 13, 21, 22, 23, 31, 32, 33)
' Loop through the array
For i = LBound(classArray) To UBound(classArray)
' Search the range B:V
With wsSource.<REDACTED>:V")
Set c = .Find(classArray(i), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = <REDACTED>
Do
' Copy the cell below the found cell and the cell to its right to the destination sheet
wsDest.Cells(i + 2, "B").Value = <REDACTED>, 0).Value
wsDest.Cells(i + 2, "C").Value = <REDACTED>, 1).Value
' Continue searching from after the found cell
Set c = .FindNext(c)
' Loop until you find the first found cell again
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Next i
Dim wsSource As <REDACTED> wsDest As <REDACTED> classArray As <REDACTED> i As Integer
Dim j As Long
Dim c As Range
Dim firstAddress As String
Dim pasteCol As Integer
Set wsSource = ThisWorkbook.Sheets("先生別")
Set wsDest = ThisWorkbook.Sheets.Add
wsDest.Name = "クラス別"
classArray = <REDACTED>, 12, 13, 21, 22, 23, 31, 32, 33)
pasteCol = 2 ' start paste from column B
' Loop through the array
For i = LBound(classArray) To UBound(classArray)
' Search the range B:V
For j = 2 To 22 ' Corresponds to columns B to V
With wsSource.Columns(j)
Set c = .Find(classArray(i), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = <REDACTED>
Do
' Copy the cell below the found cell to the destination sheet at the respective column
wsDest.Cells(i + 2, pasteCol).Value = c.Offset(1, 0).Value
' Continue searching from after the found cell
Set c = .FindNext(c)
' Loop until you find the first found cell again
Loop While Not c Is Nothing And c.Address <> firstAddress
' Move to the next column for the next paste
pasteCol = pasteCol + 1
End If
End With
Next j
pasteCol = 2 ' reset column for the next class number
Next i
Dim wsSource As <REDACTED> wsDest As <REDACTED> classArray As <REDACTED> i As Integer
Dim j As Long
Dim c As Range
Dim firstAddress As String
Dim pasteCol As Integer
Set wsSource = ThisWorkbook.Sheets("先生別")
Set wsDest = ThisWorkbook.Sheets.Add
wsDest.Name = "クラス別"
classArray = <REDACTED>, 12, 13, 21, 22, 23, 31, 32, 33)
pasteCol = 2 ' start paste from column B
' Loop through the array
For i = LBound(classArray) To UBound(classArray)
' Search the range B:V
For j = 2 To 22 ' Corresponds to columns B to V
With wsSource.Columns(j)
Set c = .Find(classArray(i), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = <REDACTED>
Do
' Copy the cell below the found cell to the destination sheet at the respective column
wsDest.Cells(i + 2, pasteCol).Value = c.Offset(1, 0).Value
' Continue searching from after the found cell
Set c = .FindNext(c)
' Loop until you find the first found cell again
Loop While Not c Is Nothing And c.Address <> firstAddress
' Move to the next column for the next paste
pasteCol = pasteCol + 1
Else
' If class number not found in the column, fill it with "データなし"
wsDest.Cells(i + 2, pasteCol).Value = "データなし"
pasteCol = pasteCol + 1
End If
End With
Next j
pasteCol = 2 ' reset column for the next class number
Next i
“シート「先生別」のB列からV列に対して、[クラスの配列]を1つずつ検索する 検索してヒットしたセルの1つ下のセルの内容をコピーする….” Conversation with gpt-4, from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84tpht8jvqh1xhrfvgavx6a