1

新しい言語の構文は習得が難しい場合があります。私は 1 日前から VBA に優れています。下のどこが間違っているのでしょう。

ユーザーが選択したセルの行に色を付けようとしています

Sub color()
    Dim R As Range
    Dim I As Integer
    Dim P As Object
    I = 1
    R = Selection
    For Each P In R
        If I Mod 2 = 0 Then
             P.Interior.ColorIndex = 36
        Else
            P.Interior.ColorIndex = 40
        I = I + 1
    Next P
End Sub

私が得るエラーはNext Without forです

4

1 に答える 1

1

Siddarth, his question was "The error I get is Next Without for". I had corrected the error by adding "End IF". Anyways here is the correct code: ---

Sub color()
  Dim R As Range
  Dim I As Integer
    Dim P As Object
  I = 1
  'R = ActiveWindow.Selection
  For Each P In ActiveWindow.Selection
      If I Mod 2 = 0 Then
           P.Interior.ColorIndex = 36
      Else
          P.Interior.ColorIndex = 40
      End If
      I = I + 1
    Next P
 End Sub

6 and 7th line also can be changed as below:

  Set R = ActiveWindow.Selection
  For Each P In R
于 2013-04-21T02:47:16.397 に答える