调用sub定义了2个参数

时间:2017-04-07 15:32:49

标签: excel vba excel-vba

我试图在我的主要中调用一个sub,并且基本上用这个sub填充另一列。但我收到语法错误。这是为什么?

Option Explicit

Private Sub Form_Load()
    Dim mystring As String, i As Long, asciinum As String, f As Long

    With Worksheets("sheet1")
        For f = 2 To .Cells(.Rows.Count, "I").End(xlUp).Row
            mystring = .Cells(f, "I").Value2
            prueba1 (mystring, f)
        Next f
    End With
End Sub

Sub prueba1(mystring, index As Long)
Dim i As Long, asciinum As String

            For i = 1 To Len(mystring)
                asciinum = LCase(Mid(mystring, i, 1))
                If asciinum Like "[aeiou]" Then
                    .Cells(index, "M") = "First Vowel " + asciinum
                    Exit For
                End If
            Next i
End Sub

1 个答案:

答案 0 :(得分:2)

  • prueba1 (mystring, f)应为prueba1 mystring, f
  • prueba1(mystring, index As Long)应为prueba1(mystring AS STRING, index As Long)
  • 在一个With ... End With中没有父工作表在prueba1中,但您使用的是.Cells而不是Cells。至少应该是Worksheets("sheet1").Cells(index, "M") = "First Vowel " + asciinum