[[20210713171435]] 『実行時エラー91「オブジェクト変数または With ブ』(hiro) ページの最後に飛ぶ

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

 

『実行時エラー91「オブジェクト変数または With ブロック変数が設定されていません』(hiro)

起動ボタンをクリックしてVBAを起動させると上記のエラーが出てしまい、対処できずに困っております。どなたかご教示お願いします。
エラー箇所
With Intersect(.AutoFilter.sh.Range.Resize(.AutoFilter.sh.Range.Rows.Count - 1).Offset(1), .sh.Columns("B")).SpecialCells(xlCellTypeVisible)

コード全文

Public Sub MakiGraph()

'###変数定義###

'グラフ作成用ループカウンター
Dim i As Long
'項目名用ループカウンター
Dim x As Long
'ワークシート処理用
Dim WS As Worksheet
'最終行取得
Dim EndRow As Long
'最終列取得
Dim EndCol As Long
'ワークシート代入用変数
Dim sh As Worksheet

'データ加工用変数

Dim d As String
'データ加工用変数
Dim str As String
'データ加工用変数
Dim strCell As String
'データ加工用変数
Dim strTitle As String
'データ加工用変数
Dim strJoin As String
'データ加工用変数
Dim strDay As String
'データ加工用変数
Dim strtime As String
'ループ用
Dim ab As Long

'グラフ作成用ループカウンター
Dim aa As Long

str = "CELL_"
'「graph」の有無を確認しなければ作成しデータを削除
For Each WS In Worksheets

    If WS.Name = "graph" Then
        Application.DisplayAlerts = False
        WS.Delete
        Application.DisplayAlerts = True
        Exit For
    End If
Next WS

'ワークシートアクティブ
Worksheets.Add
ActiveSheet.Name = "graph"
Sheets("graph").Activate

'シート指定用変数
Set sh = Sheets("data")

'範囲指定用処理
Dim First_Row As Long
Dim Lost_Row As Long

    With ActiveSheet
        'If Not .AutoFilterMode Then Exit Function
        With Intersect(.AutoFilter.sh.Range.Resize(.AutoFilter.sh.Range.Rows.Count - 1).Offset(1), .sh.Columns("B")).SpecialCells(xlCellTypeVisible)
        'Debug.Print .Areas(1).Rows(1).Address
        'Debug.Print .Areas(.Areas.count).Rows(.Areas(.Areas.count).Rows.count).Address

        First_Row = .Areas(1).Row
        Lost_Row = .Areas(.Areas.Count).Rows(.Areas(.Areas.Count).Rows.Count).Row

        MsgBox First_Row
        MsgBox Lost_Row

    End With
End With

'###########グラフ作成
'初期値 セル[F1]の No1_接続成功率(発信+着信)から開始するため

'グラフ作成に必要な最終列を取得

EndCol = sh.Cells(2, Columns.Count).End(xlToLeft).Column

x = 6

'グラフ加工用処理
d = " "

'グラフを一項目づつ作成するためのループ
For i = 2 To EndCol

    'グラフ作成を行うためシートを活性

'グラフタイトル加工用処理
strCell = sh.Cells(2, 2).Text
strTitle = sh.Cells(1, x).Text
strJoin = str + strCell + d + strTitle

    'グラフ作成
        With ActiveSheet.Shapes.AddChart.Chart

            'グラフ種類設定
            .ChartType = xlLine

            'グラフ範囲指定
            .SetSourceData Source:=Union(sh.Range(sh.Cells(First_Row, 4), sh.Cells(Lost_Row, 4)), _
            sh.Range((sh.Cells(First_Row, x)), sh.Cells(Lost_Row, x)))

            'グラフタイトル表示
            .HasTitle = True

            'タイトル文字列設定
            '.ChartTitle.Text = sh.Cells(1, x)
            .ChartTitle.Text = strJoin

            '凡例を削除
            .Legend.Delete

            'グラフ位置の設定
            .Parent.Top = Range("B" & ((i - 2) * 20 + 2)).Top
            .Parent.Left = Range("B" & ((i - 2) * 15 + 2)).Left

        'グラフ作成用
        End With

        'グラフサイズ設定
        With ActiveSheet.ChartObjects
            .Height = 300
            .Width = 1200

        End With

'グラフ項目移動用カウンター
x = x + 1
Next i
'ループ終了

End Sub

< 使用 Excel:Office365、使用 OS:Windows10 >


 .AutoFilter.sh.Range
 shってなんですか?
(´・ω・`) 2021/07/13(火) 17:48

 shってなんですか?
 
 ↑
'シート指定用変数
Set sh = Sheets("data")
ここで使用するのに付けました。
(hiro) 2021/07/13(火) 18:19

 shってなんですかって、別にあなたの考えを教えてほしいわけじゃないですよ
 そこがおかしいって指摘してるんです

 そこだけがおかしいわけではないですが
(´・ω・`) 2021/07/13(火) 20:40

コメント返信:

[ 一覧(最新更新順) ]


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