|    | 
     ▼マップー さん: 
 
>Private Sub Worksheet_Change(ByVal Target As Range) 
>  と 
>Private Sub Worksheet_Activate() 
>  は 
> 
>一つにまとめられるものでしょうか? 
 
用途が違いますから、纏められないでしょう。 
 
 
>'5行目以降でE列に医療機関名を漢字で入力すると、D列に振り仮名を振り、F列に"なし"と入力する 
>Private Sub Worksheet_Change(ByVal Target As Range) 
>  Dim rng As Range 
>  Dim crng As Range 
>  Application.EnableEvents = False 
>   
>LastRow = Range("E65536").End(xlUp).Row 
> 
>For R = 5 To LastRow 
>  Set rng = Application.Intersect(Target, Range("E:E")) 
>  If Not rng Is Nothing Then 
>    For Each crng In rng 
>     With crng 
>       .Offset(0, -1).Value = _ 
>        Evaluate("asc(phonetic(" & .Address & "))") 
>       End With 
>     Next 
>    End If 
>  If Target.Column = 5 Then 
>    Cells(Target.Row, "F") = "なし" 
>    End If 
>    Next R 
>  Application.EnableEvents = True 
>End Sub 
 
上のコードだったら、一般のシート関数で作成しても良いのでは? 
っと思いましたが。 
 
下のコードでは何を目的に作成されているのか、これだけでは分かりませんが 
シートがActivateされた時に動作するようにコードが書かれているのですから 
用途が違のでしょう。 
 
> 
> 
>'  シート医療機関がアクティブになった時の処理 
>Private Sub Worksheet_Activate() 
>Dim myRange As Range 
>Dim FindCell As Range 
>Dim LastRow As Long 
>Dim LastClm As Integer 
>Dim R As Long 
> 
>If Range("F2").Value = "" Then Exit Sub 
> 
>LastRow = Range("E65536").End(xlUp).Row 
> 
>For R = 5 To LastRow 
>Set myRange = Range(Cells(R, "G"), Cells(R, "IV").End(xlToLeft)) 
>If WorksheetFunction.CountIf(myRange, Range("F2").Value) > 0 Then 
>Cells(R, "B").Value = 0 
>Else 
>Cells(R, "B").Value = 1 
>End If 
>Next R 
> 
>If WorksheetFunction.CountIf(Range("B5:B" & LastRow), 1) = 0 Then Exit Sub 
> 
>LastClm = 5 
> 
>For R = 5 To LastRow 
>If LastClm < Cells(R, "IV").End(xlToLeft).Column Then 
>LastClm = Cells(R, "IV").End(xlToLeft).Column 
>End If 
>Next R 
> 
>Set myRange = Range("A5", Cells(LastRow, LastClm)) 
> 
>myRange.Sort Key1:=Range("B5"), Order1:=xlAscending, _ 
>Key2:=Range("D5"), Order1:=xlAscending, _ 
>Header:=xlGuess, OrderCustom:=1, MatchCase:=False 
> Range("E5").Select 
> 
>End Sub 
 | 
     
    
   |