• ベストアンサー

エクセル マクロ プログレスバーの表示について

拙いですが、以下のようなマクロを組みました。このマクロが稼働していることを、画面上にプログレスバーを表示して進捗状況として示したいのですが、よくわかりません。どのようなマクロを組んだらよいか、お教え下さい。 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sub 時間割のコピー1() Dim j As Integer Application.ScreenUpdating = False Range("BF20:BF30").Name = "理系1" Range("BH20:BH30").Name = "理系2" Range("BJ20:BJ30").Name = "理系3" Range("BL20:BL30").Name = "英国1" Range("BN20:BN30").Name = "英国2" Range("BP20:BP30").Name = "英国3" Range("BR20:BR30").Name = "数社1" Range("BT20:BT30").Name = "数社2" Range("BV20:BV30").Name = "数社3" Range("理系1").Select Selection.Copy Range("AG20").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("AG20").Activate Do Until ActiveCell.Offset(1, -4).Value = "" ActiveCell.Offset(1, 0).Select If ActiveCell = "" Then ActiveCell.ClearContents End If Loop Range("AG20:AH20").Select Selection.Activate For j = 1 To 10 With Selection.Offset(j, 0) .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .MergeCells = True End With Next j With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .MergeCells = True End With Range("理系2").Select 以下、この形が8回繰り返されます End Sub

質問者が選んだベストアンサー

  • ベストアンサー
  • imogasi
  • ベストアンサー率27% (4737/17068)
回答No.2

#1でご紹介の、記事の初めの方に、いみじくも書かれています。 >プログレスバーを作るのに必要な事、以下に。 結局、この質問の作業の進捗率を正しく捉えられるか、ということを考えてみましたか。 観念的に初めと終わりを考え、途中に10%の処理が終わった瞬間があるはずだ、といった考えで考えて質問していませんか。 全体の時間というのはなかなか処理コードからでは出てこないものと思います。 繰り返しがある場合(レコードなどファイルIOを行うなど、内部処理と比較にならない時間を要するものの繰り返しなど)、毎回繰り返しは同じ時間と看做して、進捗率に看做す手はあるでしょう。しかし毎回繰り返しは同じ時間といえるかどうか、繰り返し外で時間がかかるタイプの処理ならば、どうするのか。 上記記事などには書いてなかったと思うのですが、いっそテストや本番の処理時間を実測して、毎回変わらないとして、終了が100秒後として10秒経ったら10%の表示をしてしまうのもあるような気がする。しかしこの仮定は怪しい。 ーーー 質問の>プログレスバーを表示や進捗率が算出されて表示するコードなど実例がWEB上に沢山あるで章しょう。 ーー >・・状況として示したいのですが これも質問者の趣味に回答者がつき合わされているようなもので、質問のコードの実行では、すぐ終わって、バー表地などの対象外ではないですか。 基本的なこと以外は、思いついたあることをしたい場合は、質問者で調べて勉強すべきです。

ame2008
質問者

お礼

回答をいただき、ありがとうございました。まだまだ勉強不足であることを通関しました。

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (1)

  • xls88
  • ベストアンサー率56% (669/1189)
回答No.1

Web検索すれば参考ページがヒットしますよ。 プログレスバー http://www.h3.dion.ne.jp/~sakatsu/ProgressBarTopic.htm

ame2008
質問者

お礼

ありがとうございました。もう一度勉強をし直します。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • 【自作マクロ】いらない部分を削除していただきたい。

    自分で行ってみたマクロですが、長く、見づらいです。 いらない部分を削除していただける方がいましたら、お願いいたします。 作業としては、 /////////////////////////////////// あああ いいい ううう えええ おおお かかか      あかさたなはまやらわん の、「あかさたなはまやらわん」を削除し、セルの結合を解除し、 あああ、いいい など文字のあるセルと下のセルを結合して格子をつける。 /////////////////////////////////// Sub 項目を1行にして摘要を削除する() ' ' 項目を1行にして摘要を削除する Macro ' ' Range("C7:H7").Select ActiveCell.FormulaR1C1 = "" Range("C7:H7").Select With Selection .HorizontalAlignment = xlGeneral .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With Selection.UnMerge Range("C6:C7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("D6:D7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("E6:E7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("F6:F7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("G6:G7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("H6:H7").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("C6:H7").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With End Sub

  • エクセルマクロで教えてください

    エクセル2003です。 自動マクロで下記のようなマクロを造ったんですが Selection.End(xlDown).Select   Range("A29:D29").Select  ■A29を止まったセルの番号にしたいのです。(A**からD**まで)     With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("A30").Select ■A30を止まったセルの番号にしたいのです 以上2箇所の指定を教えていただけますでしょうか。 よろしくお願いいたします。

  • エクセルのマクロ セルの結合プロシージャを教えてください。

    マクロの記憶でのプロシージャを Rangeを変数型にしたいのです。 行も列も定めまずに、範囲はA1:BX45です。 Offsetを使うのか、もう何がなんだかわからないので 教えてください!! マクロの記憶でのプロシージャです。 ↓ Keyboard Shortcut: Ctrl+d ' End Sub Range("R26:T27").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = True .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge End Sub

  • セル結合と列挿入

    マクロの記録を使い書いて見ましたが、1行置きに3行挿入し 、A2:A5 , B2:B5 ,C2:C5 ,D2,D5 言う感じでセル結合を5000行まで行い、最後にD、E列、列の挿入したいのですが、どのように書けば宜しいでしょうか? すでに、データが入っています。 Sub Macro1() Rows("3:5").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Rows("7:9").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("A2:A5").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("B2:B5").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("C2:C5").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("A6:A9").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("B6:B9").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("C6:C9").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Columns("D:E").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Selection.ColumnWidth = 18.88 Range("A2:A5").Select End Sub

  • EXCELのマクロについて

    お世話になっております。 以下のマクロを1万行分繰り返したいのですが、回数を1万回と指定する構文を 教えてください。よろしくお願いします。 Sub Macro16() ' ' Macro16 Macro ' ' Keyboard Shortcut: Ctrl+Shift+Z ' ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove ActiveCell.Offset(-1, 0).Range("A1:M1").Select Selection.Copy ActiveCell.Offset(1, 0).Range("A1").Select ActiveSheet.Paste ActiveCell.Offset(-1, 2).Range("A1").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "7/5/1905" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "7/6/1905" ActiveCell.Offset(1, -2).Range("A1").Select End Sub

  • エクセルマクロについて

    最終行の1つ下の行に100000と入力したいですが Range("b65536").Select Selection.End(xlUp).Select ActiveCell.Offset(0, 1).Value = 100000 としてもうまく行きません Selection.End(xlUp).Select この部分だけで なんとかなるのでしょうか よろしくお願い致します

  • マクロ:セルの範囲指定

    エクセルマクロで困っています。 セルの範囲指定をしようとしています。 初心者過ぎて、よくわかりません。 現在のマクロ↓ Sub 済() If ActiveCell.Column = 21 Then Selection.FormatConditions.Delete '条件付き書式削除 With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With ActiveCell.Offset(0, 1).Select With Selection.Interior .ColorIndex = 16 .Pattern = xlSolid End With '色変え判定セル書き換え ActiveCell.Offset(0, 5).Select ActiveCell.FormulaR1C1 = "77" ActiveCell.Offset(0, -5).Select Else answer = MsgBox("U列を選択して下さい", vbCritical) End If End Sub やりたい事は、下記の通りです。 列Uがアクティブの時にU~ACの行を塗りつぶし。 列は変動します。 今は、やり方がよく分からなかったため オフセットで一つ一つ塗りつぶしてます。 マクロを組みすぎてファイルが重くなって困っています。 回答よろしくお願いいたします。

  • Excel VBAで表組みしたらデバック発生

    Excel VBAの初心者です。Windows Vistaで Excel2007を使っています。 表をマクロの実行で作成したいと思っています。 何もないエクセルブックより 「開発」→「マクロの記録」→「相対参照」 →「表の作成」→「記録終了」→「相対参照で記録の解除」 →「エクセルマクロ有効ブックで保存」 ところがこのマクロ記録が入ったブックを再度立ち上げ、 表をオールクリアにし、マクロボタンより表作成を実行 させようとすると、次のエラーメッセージがでました。 『実行時エラー'9' インデックスが有効範囲にありません。』 デバックからModule1をみると以下の記述となっていました。 Sub 表組み() ' ' 表組み Macro ' ' ActiveCell.Range("A1:E5").Select Selection.Copy Windows("Book1").Activate ActiveSheet.Paste ActiveCell.Columns("A:A").EntireColumn.Select ActiveCell.Rows("1:1").EntireRow.RowHeight = 11.25 ActiveCell.Rows("1:5").EntireRow.Select Selection.RowHeight = 21.75 ActiveCell.Columns("A:A").EntireColumn.ColumnWidth = 14.88 ActiveCell.Offset(0, 4).Range("A1").Select Application.CutCopyMode = False With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With ActiveCell.Offset(1, -3).Range("A1:D4").Select Selection.NumberFormatLocal = "#,##0_ " ActiveCell.Select ActiveCell.FormulaR1C1 = "78000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "102000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "9800" ActiveCell.Offset(-2, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "65000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "204000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "500" ActiveCell.Offset(-2, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "86000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "151000" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "10200" ActiveCell.Offset(-2, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" ActiveCell.Offset(0, -3).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" ActiveCell.Offset(-4, -2).Range("A1:D1").Select Selection.AutoFilter End Sub 上から9行目(?)のWindows("Book1").Activateに 黄色い矢印が示され、また行全体が黄色く四角に 覆われていました。 おそらくこの記述に問題があると思いますが、 どんな記述に変えたらいいのか分かりません。 Excel VBAにお詳しい方ご教示願います。 なお、マクロで作成したい図を添付いたします。 参考にしていただければ幸いです。

  • 任意のセルでマクロを実行させたい

    アクティブセルにマクロを実行させたいのですがうまくいきません。 2007のエクセルを使用しています。 (1)命令文で指定しているセル(G9:G11)をJ9:J11やR14:R16等でも使用したい。 (2)また作成したマクロを同シート内オートシェイプに登録したい。 よろしくお願いいたします。 Sub Macro2() ' ' Macro2 Macro ' ' Range("G9:G11").Select Selection.ClearContents With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .Orientation = xlVertical .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With With Selection.Font .Name = "MS P明朝" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 16777164 .TintAndShade = 0 .PatternTintAndShade = 0 End With ActiveCell.FormulaR1C1 = "搬入" With ActiveCell.Characters(Start:=1, Length:=2).Font .Name = "MS P明朝" .FontStyle = "標準" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With ActiveCell.Characters(1, 2).PhoneticCharacters = "ハンニュウ" Range("G12").Select End Sub

  • エクセルマクロが重い

    こんにちは。 ご教授くださいませ。 すでに先方が作っているエクセルのシートがありまして、 そのシートの表組み規則にのっとって入力するユーザーフォーム を私のほうで作ったのですが、重いです。 selectの多用はだめ!というところまでは調べたのですが じゃあどうしたらいいかわかりません。 ■ '--------------------8時から If OptionButton1.Value = True Then ActiveCell.Offset(3, -1).Range("A1").Select ActiveCell = UserForm3.TextBox1.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox2.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox3.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox4.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox5.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox6.Value ActiveCell.Offset(3, 0).Range("A1").Select ActiveCell = UserForm3.TextBox12.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox11.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox10.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox9.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox8.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox7.Value ActiveCell.Offset(3, 0).Range("A1").Select ActiveCell = UserForm3.TextBox13.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox14.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox15.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox16.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox17.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox18.Value ActiveCell.Offset(3, 0).Range("A1").Select ActiveCell = UserForm3.TextBox24.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox23.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox22.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox21.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox20.Value ActiveCell.Offset(0, -1).Range("A1").Select ActiveCell = UserForm3.TextBox19.Value ActiveCell.Offset(3, 0).Range("A1").Select ActiveCell = UserForm3.TextBox25.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox26.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox27.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox28.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox29.Value ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell = UserForm3.TextBox30.Value 'ActiveWorkbook.Save MsgBox "入力しました。", vbInformation, "確認" End If '--------------------8時から(END ■ 基本の流れは... 最初にオプションボタン3つのどれか1個の 選択を求め、その条件に応じて 始基点となるセルが変わります。 で、あとは与えられた表組みを縦や横に 移動しながら、対応するテキストボックスの 値を入れる、という 我ながら頭の悪い方法で^^; .selectではない、スマートな方法があればと思います。 ぜひお知恵を!

専門家に質問してみよう