エクセルマクロのメモ

結構面倒くさい(;´Д`)

Option Explicit

Sub OnClick_Search()
    Dim w As Worksheet
    Dim c As Range
    Dim s() As String
    Dim firstAddress As String
    Dim i As Integer
    
    Set w = ActiveSheet
    If w Is Nothing Then MsgBox "ワークシートエラー"
    'w.Cells(1, 1).Activate
    ActiveCell.SpecialCells(xlLastCell).Select
    Set c = w.Cells.Find("01", after:=ActiveCell, LookAt:=xlWhole)
    If Not c Is Nothing Then
        firstAddress = c.Address
        i = 0
        Do
            i = i + 1
            ReDim Preserve s(i)
            s(i) = w.Cells(c.Row, 2)
            Set c = w.Cells.FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    MsgBox "終了です。"
End Sub