2016-10-24 3 views
0

VBAスクリプトを実行して、貼り付けたデータのハイフンをExcelに自動的に大文字にして削除します。複数行のデータがペーストされている場合、このスクリプトは、シングルラインペースト(単一セル)に大きな動作しますが、実行されません(データを変更するには、何もしません)以下は、私のコードです:。貼り付けられたデータの複数行のスクリプトの置換/置き換え

Private Sub worksheet_change(ByVal target As Range) 
    Application.EnableEvents = False 
     With target 
     On Error Resume Next 
     Dim rng As Range 
     Set rng = Range("A:U") 

     If Not Intersect(target, rng) Is Nothing Then 
      If Not .HasFormula Then 
       .Value = UCase(.Value) 
       .Value = Replace(.Value, "-", "") 
      End If 
     End If 
    End With 
    Application.EnableEvents = True 
End Sub 

答えて

0

てみてくださいこの

Private Sub worksheet_change(ByVal target As Range) 
    Application.EnableEvents = False 
    With target 
     On Error Resume Next 
     Dim rng As Range 
     Dim cell As Range 
     Set rng = Range("A:U") 

     If Not Intersect(target, rng) Is Nothing Then 
      For Each cell in target 
       If Not cell.HasFormula Then 
        cell.Value = UCase(cell.Value) 
        cell.Value = Replace(cell.Value, "-", "") 
       End If 
      next cell 
     End If 
    End With 
    Application.EnableEvents = True 
End Sub 
+0

@ElleryHiggins私はちょうど新しい編集を入れました。オペレータの割り当て側を変更するのを忘れた – PartyHatPanda

+0

完璧な作品!どうもありがとうございます!これは非常に時間を節約します! –

+0

私は助けてくれると嬉しいです。それがあなたのために働く場合は、答えとしてあなたの質問を閉じるためにこれを正しいとマークしてください! – PartyHatPanda

関連する問題