? asked in 電腦與網際網路程式設計 · 9 years ago

VB所用的print在VBA中,要改成什麼才好?

大家好!我參考了VB6的範例,想要在Excel 中的VBA來練習,我用了以下的例子,歌唱大賽5位歌者進入決賽,有10位評審參與評分工作,試寫一程式記錄10位評審給5位歌者的分數,最後再計算每位歌者的總分及平均分數。Private Sub CommandButton1_Click()Dim score(4, 9)For i = 0 To 4Sum = 0For j = 0 To 9s = "輸入第" & i + 1 & "位歌者,第" & j + 1 & "位評審的分數"score(i, j) = Val(InputBox(s))Sum = Sum + score(i, j)Next j Print "第"; i + 1; "位歌者總分="; Sum, "平均分數="; Sum / 10 Next i End Sub 執行後發現 print 這一行錯,請問這裏所用的print在VBA中,要改成什麼才好?我試過用msgbox好像也不行,不知是那裏錯,感謝大家!

1 Answer

Rating
  • 世賢
    Lv 7
    9 years ago
    Favorite Answer

    Option Explicit

    Private Sub CommandButton1_Click()

     Dim score(4, 9)

     Dim Sum As Integer

     Dim i As Integer, j As Integer

     Dim s As String

     

     For i = 0 To 4

      Sum = 0

      For j = 0 To 9

       s = "輸入第" & i + 1 & "位歌者,第" & j + 1 & "位評審的分數"

       score(i, j) = Val(InputBox(s))

       Sum = Sum + score(i, j)

      Next j

      Range("A" & i + 1) = "第" & i + 1 & "位歌者總分=" & Sum 'A欄為總分

      Range("B" & i + 1) = "平均分數=" & Sum / 10 'B欄為平均分數

      Columns("A:B").EntireColumn.AutoFit '自動調整欄寬

     Next i

    End Sub

    Source(s): Excel 2003 VBA and Me
    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.