List separator or vba ошибка

Hello,
  • Remove From My Forums
  • Question

  • Hello,

    Please, advise me where is the error in the following code:

    Function Filter(Number As Integer, Name As String)
       Select Case Name
        Case «aaa»
            Filter = True
        Case «bbb»
            Filter = True
        Case Else
            Select Case Number
                Case 79001
                    Filter = True
                Case Else
                    Filter = False
            End Select
        End Select
    End Function

    Thank you in advance!

    • Edited by

      Friday, May 26, 2017 10:26 PM

Answers

  • Function ABCDEFG(Number1 As Integer, Name1 As String)

        ….

            Select Case Number1
                Case 79001

    Hi Kate,

    You can use nested Select Case statements, as you have already demonstrated in your example.

    The problem lies in  Case 79001. This value is too large for an Integer. You can better use the Long type..

    You can further simplify your code:

    Function ABCDEFG(Number1 As Long, Name1 As String) As Boolean
        Select Case Name1
        Case "aaa", "bbb": ABCDEFG = True
        Case Else
            Select Case Number1
            Case 79001: ABCDEFG = True
            End Select
        End Select
     End Function
    

    as this function defaults False as result.

    Imb.

    • Marked as answer by
      KateStsv
      Saturday, May 27, 2017 10:38 PM

  • ABCDEFG(20001;»gh»)

    «Compile error: Expected list separator or )»

    Hi Kate,

    The arguments are to be separated by a comma:

        boolean_result = ABCDEFG(20001,»gh»)

    Imb.

    • Marked as answer by
      KateStsv
      Saturday, May 27, 2017 10:38 PM

  • Remove From My Forums
  • Question

  • Hi. I am a newbie to Visual Basic. I have made a user form in Excel that sends the info to a hidden sheet. When I test the user form, it says compile error — expected: list separator or ). I am baffled about how to solve it. Below is the code:

    Private Sub CommandSubmit_Click()
    Dim lRow As Long
    Dim lPart As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Year9StudentCommunication")
    
    'find first empty row in database
    lRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
    
    'check for a part number
    If Trim(Me.TextName.Value) = "" Then
      Me.TextName.SetFocus
      MsgBox "Please enter a student name"
      Exit Sub
    End If
    
    'copy the data to the database
    With ws
      .Cells(lRow, 1).Value = Me.TextName.Value
      .Cells(lRow, 2).Value = Me.TextSurname.Value
      .Cells(lRow, 3).Value = Me.ComboRegGroup.Value
      .Cells(lRow, 4).Value = Me.TextConcern.Value
      .Cells(lRow, 5).Value = Me.ComboContact.Value
      .Cells(1Row, 6).Value = Me.ComboOutcome.Value
      .Cells(1Row, 7).Value = Me.TextDate.Value
      .Cells(1Row, 8).Value = Me.TextStaff.Value
    
    End With
    
    'clear the data
    Me.TextName.Value = ""
    Me.TextSurname.Value = ""
    Me.ComboRegGroup.Value = ""
    Me.TextConcern.Value = ""
    Me.ComboContact.Value = ""
    Me.ComboOutcome.Value = ""
    Me.TextDate.Value = ""
    Me.TextStaff.Value = ""
    Me.TextName.SetFocus
    
    End Sub

    If I delete the highlighted rows, the user form works. If I leave them in, that’s when the error message appears. I suspect it is something really obvious.

    Please help!! (If you could explain what I’m doing wrong, that would be really helpful!)

    Chris

Answers

  • In the three highlighted lines, you have used the digit 1 instead of the letter l (lower case L): if you change 1row to lrow, it should be OK.


    Regards, Hans Vogelaar

    • Marked as answer by

      Saturday, December 17, 2011 3:49 PM

  • Remove From My Forums
  • Question

  • Hi. I am a newbie to Visual Basic. I have made a user form in Excel that sends the info to a hidden sheet. When I test the user form, it says compile error — expected: list separator or ). I am baffled about how to solve it. Below is the code:

    Private Sub CommandSubmit_Click()
    Dim lRow As Long
    Dim lPart As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Year9StudentCommunication")
    
    'find first empty row in database
    lRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
    
    'check for a part number
    If Trim(Me.TextName.Value) = "" Then
      Me.TextName.SetFocus
      MsgBox "Please enter a student name"
      Exit Sub
    End If
    
    'copy the data to the database
    With ws
      .Cells(lRow, 1).Value = Me.TextName.Value
      .Cells(lRow, 2).Value = Me.TextSurname.Value
      .Cells(lRow, 3).Value = Me.ComboRegGroup.Value
      .Cells(lRow, 4).Value = Me.TextConcern.Value
      .Cells(lRow, 5).Value = Me.ComboContact.Value
      .Cells(1Row, 6).Value = Me.ComboOutcome.Value
      .Cells(1Row, 7).Value = Me.TextDate.Value
      .Cells(1Row, 8).Value = Me.TextStaff.Value
    
    End With
    
    'clear the data
    Me.TextName.Value = ""
    Me.TextSurname.Value = ""
    Me.ComboRegGroup.Value = ""
    Me.TextConcern.Value = ""
    Me.ComboContact.Value = ""
    Me.ComboOutcome.Value = ""
    Me.TextDate.Value = ""
    Me.TextStaff.Value = ""
    Me.TextName.SetFocus
    
    End Sub

    If I delete the highlighted rows, the user form works. If I leave them in, that’s when the error message appears. I suspect it is something really obvious.

    Please help!! (If you could explain what I’m doing wrong, that would be really helpful!)

    Chris

Answers

  • In the three highlighted lines, you have used the digit 1 instead of the letter l (lower case L): if you change 1row to lrow, it should be OK.


    Regards, Hans Vogelaar

    • Marked as answer by

      Saturday, December 17, 2011 3:49 PM

Понравилась статья? Поделить с друзьями:
  • List object has no attribute replace как исправить
  • List object cannot be interpreted as an integer как исправить
  • List is empty egov mobile ошибка
  • List indices must be integers or slices not str как исправить
  • List indices must be integers or slices not str python ошибка