2014-05-11 2 views
0

다음 코드는 차트의 선 세그먼트를 삭제합니다. 나는이 단일 값 대 값의 행 $ A $ 1 반복적으로 실행하고 싶습니다 :특정 워크 시트 값의 범위에 대한 루프 차트 변경

With Sheet1.ChartObjects("Chart 1").Chart.SeriesCollection(1) 
     .Points(Sheet1.Range("$A$1:$A:$100").Value).Format.Line.Visible = msoFalse 
    End With 

:이 잘못된 구문이지만

With Sheet1.ChartObjects("Chart 1").Chart.SeriesCollection(1) 
     .Points(Sheet1.Range("$A$1").Value).Format.Line.Visible = msoFalse 
    End With 

, 일반 목적의 힘이 같이 보입니다 또한 생략하지 않으면 런타임 오류가 발생하는 범위의 일부 #NA 값이 있습니다.

이 문제에 대한 도움을 주셔서 감사합니다.

답변

0

반복 루프가 필요합니다. For/Next이 다음과 같은 목적으로 작동해야합니다.

'Declare two range variables we will use to do this: 
Dim rng as Range 'represents the entire range of ALL data cells, e.g., A1:A100 
Dim r as Range 'range iterator 

'First, define the range containing the values: 
Set rng = Sheet1.Range("A1:A100") 'Modify as needed 

'Then, begin an iteration: 

For each r in rng.Cells 
    If Not IsError(r.Value) and Not Trim(r.Value) = vbNullString Then 
     With Sheet1.ChartObjects("Chart 1").Chart.SeriesCollection(1) 
      .Points(r.Value).Format.Line.Visible = msoFalse 
     End With 
    ElseIf IsError r.Value Then 
     'if you need to do something with the #N/A values, do it here: 

    ElseIf Trim(r.Value) = vbNullString Then 
     'if you need to do something with blank cells, do it here: 

    End If 
Next 
+0

동적 이름이 지정된 범위에서 NA # 값을 제외하면 런타임 오류가 발생하지 않습니다. (또는 동적 명명 된 범위를 포함하지 않는 NA # 또는 ""값을 제외하는 다른 솔루션) – oser

+0

루프에 일부 조건부 로직을 넣기 만하면됩니다. 오류 및 빈 셀을 무시하도록 위에서 수정되었습니다. –

관련 문제