0

我对宏和 VB 完全陌生,因此将不胜感激。我有这种形式的excel数据:

Clip    PSNR-codec1     PSNR-codec2     Bit Rates 
Video1  29.426086       29.220891       94357
Video1  31.207342       31.703124       322832
Video1  34.474587       34.255598       633468
Video1  36.445279       35.479189       936961
Video1  39.093937       36.4768         1539093
Video2  41.156012       37.295318       326742
Video2  43.355358       37.684239       604494
Video2  29.95337        29.30644        1218206
Video2  32.040252       30.837518       1809751
Video2  34.194409       32.774954       2387549
Video3  35.495356       33.806537       1567065
Video3  36.395173       34.544676       2173151
Video3  37.077718       35.234943       3094348
Video3  35.681498       36.036972       3240981
Video3  171.661771      83.104314       3355959
Video4  171.247791      96.978608       5103370
Video4  185.239286      128.064048      6636778
Video4  189.115735      115.418461      8150015
Video4  185.35225       154.3189011     2345629

我的要求是在单独的表格中为每个视频创建一个“XYScatterSmooth”类型的图表。该图应在 X 轴上显示比特率,在 Y 轴上显示 PSNR。展望未来,我们还将拥有更多视频的数据。那么我该如何编写一个宏,它将为每个视频重复这些步骤(即循环应该每 5 行重复一次。5 行数据是固定数量)

Excel 版本:2010

4

1 回答 1

0

这对您提供的示例数据有用。

将所有数据放在第一张表上,删除任何其他表。您的数据需要从第 2 行开始(如上)。宏会询问您视频的总数(我发现这比循环直到一个空单元格更容易),然后在新工作表上创建图表。它将工作表命名为 Video1、Video2 等。

让我知道它是否适合你。

Private Sub BitRateCharts()

' Data should be on Sheet 1. Delete all other sheets.


    Dim nVideoNum As Integer
    nVideoNum = 1

    Dim n As Integer
    n = 1

    Dim nStart As Integer
    nStart = 2

    Dim nLast As Integer
    nLast = 6

    Dim nVideos As Integer
    nVideos = InputBox("How many videos?")

    Dim nSheetNum
    nSheetNum = ActiveSheet.Index

    Do Until n > nVideos

    nSheetNum = ActiveSheet.Index
        If nSheetNum = ThisWorkbook.Sheets.Count Then
            Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Video" & nVideoNum
        Else
        End If

            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
            ActiveChart.SetSourceData Source:=Range("Sheet1!$B$" & nStart & ":$D$" & nLast & "")
            ActiveChart.SeriesCollection(1).XValues = "=Sheet1!$D$" & nStart & ":$D$" & nLast & ""
            ActiveChart.SeriesCollection(1).Values = "=Sheet1!$B$" & nStart & ":$B$" & nLast & ""
            ActiveChart.SeriesCollection(2).XValues = "=Sheet1!$D$" & nStart & ":$D$" & nLast & ""
            ActiveChart.SeriesCollection(2).Values = "=Sheet1!$C$" & nStart & ":$C$" & nLast & ""
            ActiveChart.SeriesCollection(1).Name = "=""PSNR-Codec1"""
            ActiveChart.SeriesCollection(2).Name = "=""PSNR-codec2"""

            n = n + 1

            nVideoNum = nVideoNum + 1

            nStart = nStart + 5
            nLast = nLast + 5
    Loop

    MsgBox ("Macro Complete.")

Exit Sub

ErrMsg:

    MsgBox ("Error encountered. Macro could not complete.")


End Sub
于 2012-10-10T17:04:10.147 回答