[[20050415174700]] 『行挿入』(挿入) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『行挿入』(挿入)

教えてください。

[[20040915112925]]『1行毎に行を1行挿入したい』(み)

上記で、夏目雅子似さんのマクロを使用しているのですが

もっと処理速度を早くしたいのですが、どうすればいいでしょうか?

リストは、4〜300ぐらいまで有ります


 Application.ScreenUpdating = False で画面の書き換えを止めれば、
 その分早くなりますね。
 (sato)

 Sub 挿入()
 Dim MyRow As Long, r As Long
 Application.ScreenUpdating = False '画面の書き換えをしない
 r = Range("A65536").End(xlUp).Row
     For MyRow = r To 1 Step -1
         Rows(MyRow).EntireRow.Insert
     Next
 Application.ScreenUpdating = True  '画面の書き換えを再開する
 End Sub

 作ってみました。
 Sub 挿入()
 Dim r As Long
     Range("B1").EntireColumn.Insert
     r = Range("A65536").End(xlUp).Row
     Range("B4:B" & r).Formula = "=ROW()"
     Range("B" & r + 1 & ":B" & r * 2 - 3).Value = Range("B4:B" & r).Value
     Range("4:" & r * 2 - 3).Sort _
             Key1:=Range("B1"), _
             Order1:=xlAscending, _
             Header:=xlGuess, _
             OrderCustom:=1, _
             MatchCase:=False, _
             Orientation:=xlTopToBottom, _
             SortMethod:=xlPinYin
     Range("B:B").Delete
 End Sub
 
4行目からでしたね。ちょっとカスタマイズ。
(みやほりん)

 値だけでよいなら・・

 Sub aaaaaaaa()
 Dim x As Variant
 Dim y() As Variant
 Dim i As Long, s As Long, r As Long
    r = 1

    With ActiveSheet
        x = .Range("A1", .Range("A1").SpecialCells(xlCellTypeLastCell))

        ReDim y(UBound(x, 1) * 2, UBound(x, 2))

            For i = 1 To UBound(x, 1)
                For s = 1 To UBound(x, 2)
                    y(r, s) = x(i, s)
                Next s
                r = r + 2
            Next i

            .Cells.ClearContents
            .Range("A1", .Cells(UBound(y, 1), UBound(y, 2))).Value = y
    End With
 End Sub

  (INA)

satoさん、みやほりんさん、INAさん、ありがとうございました。

>Application.ScreenUpdating = False

勉強になりました

みやほりんさんの作っていただいたものは、あっという間でした

INAさんの作っていただいたものは、A列のものがB列に移動してしまいました・・・

何か間違ったやり方をしてしまったのでしょうか?

意味はチンプンカンプンですけど・・・

わかるようになったら楽しいだろうなー

(挿入)


 Option Base 1   ' ←が抜けてました。

 Sub aaaaaaaa()
    :

 >意味はチンプンカンプン
 セルの値を、配列変数に入れながら、
 1行分位置をずらして、セルに戻しています。

   (INA) 

INAさん、本当にありがとうございます。

すごく早くて、感動しております!!

(挿入)


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.