Option Explicit '値貼り付け後に空文字のセルをクリアするマクロ Sub MyCopyValues(ByVal oRange_Input As Range, ByVal oRange_Output As Range) Application.ScreenUpdating = False 'コピー元範囲の設定 Set oRange_Input = oRange_Input.Areas(1) 'コピー先範囲の設定 Set oRange_Output = oRange_Output.Cells(1, 1).Resize( _ oRange_Input.Rows.Count, oRange_Input.Columns.Count) 'コピー oRange_Input.Copy '値貼り付け oRange_Output.PasteSpecial Paste:=xlValues, _ Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False '空文字のセルをクリア MyReEnter oRange_Output '空文字のセルをクリア(区切り位置コマンドによる再入力) 'MyReEnter2 oRange_Output '空文字のセルをクリア(置換コマンドによる再入力) 'MyReEnter3 oRange_Output Application.ScreenUpdating = True End Sub '空文字のセルをクリアするマクロ '処理性能に問題がなければこちらを使う方が無難です。 Sub MyReEnter(ByVal oRange_Target As Range) Dim r As Range For Each r In oRange_Target.Cells If r.Value = "" Then r.ClearContents Next End Sub '空文字のセルをクリアするマクロ2 '区切り位置コマンドを使い、最も高速にセルを再入力します。 'ただし、すべてのセルを再入力するため、値が変わってしまう '可能性があります。("1-1" が "1月1日" に変化するなど。) Sub MyReEnter2(ByVal oRange_Target As Range) oRange_Target.TextToColumns Destination:=oRange_Target, _ DataType:=xlFixedWidth, FieldInfo:=Array(0, 1) End Sub '空文字のセルをクリアするマクロ3 '置換コマンドを使い、高速にセルを再入力します。 'ただし、セル書式のクリアを伴います。 Sub MyReEnter3(ByVal oRange_Target As Range) oRange_Target.Replace What:="", Replacement:="''", _ LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=True oRange_Target.ClearFormats oRange_Target.Replace What:="'", Replacement:="", _ LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=True End Sub 'テストマクロ Sub Test_MyCopyValues() MyCopyValues Range("A1:A5000"), Range("C1") End Sub