0
0

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 1 year has passed since last update.

VBA 分からん

Last updated at Posted at 2022-11-24

VBAでセミナーの参加者を自動で転帰し、シート2で曜日・時間ごとに平均参加者を計算するコードを作成中です。
ループ処理で曜日・時間を取得する事が出来ていたのに突然「引数の数が一致していません」などエラーが出るようになってしまいました。コード修正中です。

Sub 参加者自動集計()

    Dim sheet As Worksheet
    Dim sheet2 As Worksheet
    Set sheet = Worksheets("アウトプット")
    Set sheet2 = Worksheets("参加者数傾向")
    
    Dim data As String
    Dim data2 As String
    Dim data3 As String
    Dim Cdata As Date
    Dim A, B
    Dim i As Long
    Dim arry As Variant
    Dim date_time As String
    Dim myrange As Range
    Dim myObj As Range
    Dim keyword As String
    Set myrange = sheet2.Range("B5:Q5")
    Dim tbl As ListObject
    Set tbl = sheet2.ListObjects("テーブル1")
    Dim xlLastRow As Long                 'Excel自体の最終行
    Dim lastRow As Long                   '最終行
    Dim row As Integer
    
    'tbl.DataBodyRange.Select '正常にテーブル全体が取得できている
     tbl.HeaderRowRange(2).Range.Select
     tbl.ListRows(10).Range.Select
    
        For i = 5 To 6
        
         data = sheet.Cells(2, i)
         data2 = Mid(data, InStr(data, "(") + 1)
         data3 = Left(data2, InStr(data2, ")") - 1)
         
         Cdata = sheet.Cells(3, i)
         B = CStr(Cdata) 'CStrは日付などを文字列に変換する
            'Debug.Print B 文字列に変換された開催時間が全て取得出来ている
         
         date_time = data3 + B
           'Debug.Print date_time 'String型での曜日と時間が全て取得出来ている
           
         
         keyword = date_time
         
         Set myObj = myrange.Find(keyword, LookAt:=xlWhole)
            Debug.Print myObj.Column  'myObj.Column 'データが一致する列が取得できている
         
         
        Next i
    

その後

data = sheet.Cells(2, i)

data = sheet.Range("B" & i)

に戻したら直りました。
何なんだろう?

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?