跳过VBA中的行(循环/ If语句) - 图表轴边界更改

时间:2018-04-27 17:41:00

标签: vba loops if-statement charts

我有一个遍历数据的循环,并将其放在另一个工作表中以生成图表。但是,因为我有大量的数据,我想要垂直轴'根据单元格值变化的边界。我尝试创建一段代码来跟随它。但是,在本节中只读取了3行,其他行被跳过。我运行了代码然后我进入了它,当我注意到时。任何人都可以帮我弄清楚为什么这些行会被跳过?

正在跳过的行是:

cht.Axes(xlValue).MinimumScale = 10
ElseIf cell.Value >= 40 And cell.Value < 60 Then
cht.Axes(xlValue).MinimumScale = 20
ElseIf cell.Value >= 60 Then
cht.Axes(xlValue).MinimumScale = 40

这里是完整的代码:

Sub Loop()

   Range("E2").Select
    ActiveCell.Range("D1:E1").Select

Dim myPDF As String
Dim i As Long

    For counter = 5 To 21
        Sheets("Lang").Select
        Range("'Lang'!$E$" & counter & ":$F$" & counter).Select 'numbers
        Selection.Copy
        Sheets("Lang-Chart").Select
        Range("B1:C1").Select
        ActiveSheet.Paste
        Sheets("Lang").Select
        Range("'Lang'!$G$" & counter & ":$I$" & counter).Select 'labels
        Selection.Copy
        Sheets("Lang-Chart").Select
        Range("A2:C2").Select
        ActiveSheet.Paste

       Dim cht As Chart
Set cht = Worksheets("Lang-Chart").ChartObjects("Chart 2").Chart
For Each cell In Range("B1:C2")

    If cell.Value >= 10 And cell.Value < 40 Then
        cht.Axes(xlValue).MinimumScale = 10
    ElseIf cell.Value < 10 Then
        cht.Axes(xlValue).MinimumScale = 0
    ElseIf cell.Value >= 40 And cell.Value < 60 Then
        cht.Axes(xlValue).MinimumScale = 20
    ElseIf cell.Value >= 60 Then
        cht.Axes(xlValue).MinimumScale = 40
   End If
    Next cell


       ActiveSheet.ChartObjects("Chart 2").Activate
       ActiveChart.ChartArea.Select
       myPDF = "\\stchsfs\arboari$\Profile-Data\Desktop\Sample 20\c3-" & Sheets("Lang").Range("D" & i + 2).Value2 & ".pdf"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myPDF, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        i = i + 1
     Next counter

End Sub

谢谢!

0 个答案:

没有答案