2016-04-20 14 views
3

次のExcel VBAモジュールは、条件に基づいてさまざまな線分の色を変更するように設計されています。それは、個々のラインマーカーをプロットしない点を除いて、素晴らしい動作をします。この問題は、xlMarkerStyleCircle、MarketSize、MarkerBackgroundColor、およびMarkerForegroundColorの各行に明らかに存在します。私は問題が不適切なオブジェクトの命名またはオブジェクト参照の不適切なシーケンシングに関連しているかどうかはわかりません。どんな助けや提案も大歓迎です。同様に、誰かが同じ目的をより効率的にコーディングする方法を見ている場合は、自由に共有してください。Excel VBA xlMarkerStyleプロットしない

おかげで親切...

乾杯、 ジョン


Sub tropical_cyclone_track_format() 

    With ActiveSheet 
Set r = .Range("E24:E31") 
For i = 1 To .Shapes("CHART 3").Chart.SeriesCollection(1).Points.Count - 1 

    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerStyle = xlMarkerStyleCircle 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerSize = 2 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerBackgroundColor = RGB(0, 0, 0) 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerForegroundColor = RGB(0, 0, 0) 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.LineStyle = xlContinuous 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.Color = RGB(255, 255, 64) 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Transparency = 0 
    If r(i) = "1" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Weight = 1 

    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerStyle = xlMarkerStyleCircle 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerSize = 2 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerBackgroundColor = RGB(0, 0, 0) 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerForegroundColor = RGB(0, 0, 0) 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.LineStyle = xlContinuous 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.Color = RGB(255, 153, 16) 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Transparency = 0 
    If r(i) = "2" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Weight = 1 

    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerStyle = xlMarkerStyleCircle 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerSize = 2 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerBackgroundColor = RGB(0, 0, 0) 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerForegroundColor = RGB(0, 0, 0) 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.LineStyle = xlContinuous 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.Color = RGB(255, 3, 0) 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Transparency = 0 
    If r(i) = "3" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Weight = 1 

    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerStyle = xlMarkerStyleCircle 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerSize = 2 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerBackgroundColor = RGB(0, 0, 0) 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).MarkerForegroundColor = RGB(0, 0, 0) 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.LineStyle = xlContinuous 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border.Color = RGB(80, 0, 0) 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Transparency = 0 
    If r(i) = "4" Then .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Format.Line.Weight = 1 

    Next i 
    End With 

End Sub 

答えて

0

それはあなたのコードは、個々のラインマーカーをプロットしない理由についての説明を提供するので、これは半分の答えですが、あなたに正しい方法を教えてくれません。私があなたの問題を詳しく見てほしい場合は、ワークシートを提出して、チャートの詳細を評価する必要があります。

一方、あなたのコードはかなり反復的であり、したがって非効率的です。

ここでは、この2つの問題について説明します。

  1. PointオブジェクトはBorderメソッドを持っていません。これが理由コード が動作していない理由です。あなたはVBEの間、Pointオブジェクトは、F2キーを押していないものをする方法を知りたい場合は

    .Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1).Border

    :これはあなたのようなコードに書くことができないことを意味します。オブジェクトやメソッドについて詳しく知りたい場合は、analysistabs.comまたはdummies.com、次にexcel-spreadsheet.comを試してみてください。繰り返しますが、あなたがワークシートを共有する場合、私はあなたを助けることができます。

  2. あなたが タイプPointの変数pを宣言することでこの問題を回避し、右forループの後 その値を割り当てることができる32回コード

    .Shapes("CHART3").Chart.SeriesCollection(1).Points(i + 1)

    を繰り返します。私はあなたにこれを達成する方法を教えてくれますが、それが正しく機能するためには、ワークシートを共有する必要があります。

    Sub tropical_cyclone_track_format() 
    
    Dim r As Range 
    Set r = ActiveSheet.Range("E24:E31") 
    
    Dim i As Integer 
    For i = 1 To ActiveSheet.Shapes("CHART 3").Chart.SeriesCollection(1).Points.Count - 1 
    
    Dim p As Point 
    Set p = ActiveSheet.Shapes("CHART 3").Chart.SeriesCollection(1).Points(i + 1) 
    
    If r(i) = "1" Then 
        With p 
    
         p.MarkerSize = xlMarkerStyleCircle 
         p.MarkerStyle = 2 
         p.MarkerBackgroundColor = RGB(0, 0, 0) 
         p.MarkerForegroundColor = RGB(0, 0, 0) 
         p.Format.Line.Transparency = 0 
         p.Format.Line.Weight = 1 
    
        End With 
    End If 
    
    If r(i) = "2" Then 
        With p 
    
         p.MarkerSize = xlMarkerStyleCircle 
         p.MarkerStyle = 2 
         p.MarkerBackgroundColor = RGB(0, 0, 0) 
         p.MarkerForegroundColor = RGB(0, 0, 0) 
         p.Format.Line.Transparency = 0 
         p.Format.Line.Weight = 1 
    
        End With 
    End If 
    
    If r(i) = "3" Then 
        With p 
    
         p.MarkerSize = xlMarkerStyleCircle 
         p.MarkerStyle = 2 
         p.MarkerBackgroundColor = RGB(0, 0, 0) 
         p.MarkerForegroundColor = RGB(0, 0, 0) 
         p.Format.Line.Transparency = 0 
         p.Format.Line.Weight = 1 
    
        End With 
    End If 
    
    If r(i) = "4" Then 
        With p 
    
         p.MarkerSize = xlMarkerStyleCircle 
         p.MarkerStyle = 2 
         p.MarkerBackgroundColor = RGB(0, 0, 0) 
         p.MarkerForegroundColor = RGB(0, 0, 0) 
         p.Format.Line.Transparency = 0 
         p.Format.Line.Weight = 1 
    
        End With 
    End If 
    Next i 
    
    End Sub 
    
関連する問題