| 
    
     |  | すいません。教えてください。VBA初級者です。 
 「住所録」というブックの中に「私」「仕事」「抽出」という3つのシートがあります。
 で挨拶状を出そうと下記のようなマクロを組みました。がシート「仕事」のところで「形が一致しません」とマクロが中断され黄色く変わります。理由と修正箇所を教えてください。
 
 
 前提条件
 ・ インプットボックスで住所に含まれる任意の単語を入力し「私」「仕事」の住所が入っている列(「私」はL列、「仕事」はAJ列です。)でその単語が含まれている氏名(いずれのシートもB列)の名前をシート「抽出」のB列に書き出す。
 ・ シート「私」「仕事」は上2行をタイトルとして使用
 ・ シート「抽出」1行目がタイトル
 ・ シート「仕事」は住所が入っていない行があるので並び替えのち検索する
 
 ’「私」シートの住所を検索
 aa=inputbox("住所に含まれる任意の単語を入力")
 fobj = CStr(aa)
 
 With Sheets("私").Range(Sheets("私").Cells(3, 12), Sheets("私").Cells(3, 12).End(xlDown))
 Set hit_obj = .Find(fobj, LookIn:=CStr(xlValues))
 If Not hit_obj Is Nothing Then
 firstaddress = hit_obj.Address
 Do
 j1 = Right(hit_obj.Address, (Len(hit_obj.Address) - 3))
 Sheets("抽出").range("B65536").end(xlup).offset(1,0).value = Sheets("私").Cells(j1, 2).Value
 Set hit_obj = .FindNext(hit_obj)
 Loop While Not hit_obj Is Nothing And hit_obj.Address <> firstaddrress
 End If
 End With
 '「仕事」シートの住所を検索
 sheets("仕事").select
 rows("3:65536").select
 Selection.Sort Key1:=Range("AJ3"), Order1:=xlAscending, Header:=xlGuess, _
 OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
 :=xlPinYin, DataOption1:=xlSortNormal
 
 fobj = CStr(aa)
 
 With Sheets("仕事").Range(Sheets("仕事").Cells(3, 42), Sheets("仕事").Cells(3, 42).End(xlDown))  'xldown= -4121
 Set hit_obj = .Find(fobj, LookIn:=CStr(xlValues))   'xlvalue= -4163
 If Not hit_obj Is Nothing Then
 firstaddress = hit_obj.Address
 Do
 j2 = Right(hit_obj.Address, (Len(hit_obj.Address) - 3))
 Sheets("抽出").range("B65536").end(xlup).offset(1,0).value = Sheets("仕事").Cells(j2, 2).Value  ’黄色に変色  xlup= -4162  j2=$35
 Set hit_obj = .FindNext(hit_obj)
 Loop While Not hit_obj Is Nothing And hit_obj.Address <> firstaddrress
 End If
 End With
 
 という形で実行したところ「型が一致しません」と出て黄色く変色して中断されてしまいます。その際のそれぞれの値は後ろに記載している通りです。
 
 となると
 1. 「型が一致しない」とは?
 2. シート「私」では問題なく実行できたのにシート「仕事」でエラーが出るのはなぜでしょう?
 3. これを正しい構文にするとすればどこをどのように直せばよいのでしょうか?
 
 よろしくお願いします。
 
 
 |  |