Меню

List separator or ошибка vba

I am trying to create an Excel VBA button code which will copy a data in columns A8:A399, B8:B399, C8:C399, D8:D399, E8:E399, F8:F399, G8:G399, H8:H399 one of the excel workbook to another workbook without opening it. But the Code I am using gives me an error message saying:

Compile Error, Expected: List Separator or )

and it highlights the (:) in Set myData = Workbooks.SaveAs(“C:UsersathifDesktopTest_PosDataBase.xlsx”). Please tell me a solution.

Here is my Code:

Private Sub CommandButton1_Click()
    LR = Range("A399").End(xlUp).Row
    LR1 = Range("B399").End(xlUp).Row
    LR2 = Range("C399").End(xlUp).Row
    LR3 = Range("D399").End(xlUp).Row
    LR4 = Range("E399").End(xlUp).Row
    LR5 = Range("F399").End(xlUp).Row
    LR6 = Range("G399").End(xlUp).Row
    LR7 = Range("H399").End(xlUp).Row

    Dim itemIndex As String
    Dim itemNumber As String
    Dim itemDetails As String
    Dim itemPrice As Single
    Dim itemCust_nam As String
    Dim itemMobile As String
    Dim itemDate As String
    Dim itemTime As String
    Dim myData As Workbook

Worksheets(“Sheet1”).Select
    itemIndex = Range("A8:A" & LR)
    itemNumber = Range("B8:B" & LR1)
    itemDetails = Range("C8:C" & LR2)
    itemPrice = Range("D8:D" & LR3)
    itemCust_nam = Range("E8:E" & LR4)
    itemMobile = Range("F8:F" & LR5)
    itemDate = Range("G8:G" & LR6)
    itemTime = Range("H8:H" & LR7)


Set myData = Workbooks.SaveAs(“C:UsersathifDesktopTest_PosDataBase.xlsx”)

Worksheets(“Sales”).Select
Worksheets(“Sales”).Range(“A1”).Select
RowCount = Worksheets(“Sales”).Range(“A1”).CurrentRegion.Rows.Count
With Worksheets(“Sales”).Range(“A1”)
    .Offset(RowCount, 0) = itemIndex
    .Offset(RowCount, 1) = itemNumber
    .Offset(RowCount, 2) = itemDetails
    .Offset(RowCount, 3) = itemPrice
    .Offset(RowCount, 4) = itemCust_nam
    .Offset(RowCount, 5) = itemMobile
    .Offset(RowCount, 6) = ItemData
    .Offset(RowCount, 7) = itemTime
End With

myData.Save
End Sub

  • 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

  • #9

The problem is that Vlookup cannot find the value as is is expressed, in a worksheet this would display as #N/A, as you are using dates this might throw up the issue. Try converting these to their numeric value for the vlookup. Also if the date might not exist you need to handle that or it’ll bug

Code:

Dim Date1 As Long
Dim Date2 As Long
Dim MyRange As Range
Date1 = CDate("2/01/2002")
Date2 = CDate("28/02/2002")
Set MyRange = Range("A1:F3000")
Range("F4").Select
On Error Resume Next
For ror02 = 1 To Sheets.Count
x = Application.WorksheetFunction.VLookup(Date1, MyRange, 5, False)
y = Application.WorksheetFunction.VLookup(Date2, MyRange, 5, False)
ActiveCell.Value = (y - x) / x
ActiveCell.Offset(1, 0).Activate
Next ror02
End Sub

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

#1

22.09.2020 11:34:55

Уважаемые корифеи VBA, прошу помощи!  8-0

Имеется макрос, который собирает все комментарии (заметики, notes в Excel 365) в таблицу на отдельном листе. При создании комментария в его шапке автоматически появляется имя автора комментария с двоеточием (см. изображение).

При попытке просто «склеить» автора с символом двоеточия VBA Editor выдает ошибку Compile Error Expected: list separator or )

Код
Dim com As Comment
...
.Cells(i, 3).Value = Replace(com.Text, com.Author&": ", "")
...

Как правильно удалить имя автора и двоеточие, оставив только сам текст комментария?

Спасибо.

Прикрепленные файлы

  • comment.jpg (17.13 КБ)

Can’t get it, don’t need it.

 

Юрий М

Модератор

Сообщений: 60335
Регистрация: 14.09.2012

Контакты см. в профиле

Kate, из сузествующего названия темы можно понять задачу? Предложите новое — модераторы поменяют.
И небольшой файл-пример прикрепите.

 

New

Пользователь

Сообщений: 4394
Регистрация: 06.01.2013

#3

22.09.2020 11:56:51

Тема: Вернуть текст комментария без автора комментария

Вариант 1

Код
Sub Макрос1()
Dim text As String
    text = ActiveCell.Comment.text
    text = Replace(Mid(text, InStr(1, text, ":") + 1, Len(text)), Chr(10), "")
    MsgBox text
End Sub

Вариант 2

Код
Sub Макрос2()
Dim text As String
    text = Replace(Split(ActiveCell.Comment.text, ":")(1), Chr(10), "")
    MsgBox text
End Sub

Изменено: New22.09.2020 12:12:32

 

Hugo

Пользователь

Сообщений: 23100
Регистрация: 22.12.2012

А можно брать split(text,»:»,2)(1)

 

New

Пользователь

Сообщений: 4394
Регистрация: 06.01.2013

кстати, да… спасибо, Игорь. Добавил 2-й вариант в свой ответ

Изменено: New22.09.2020 12:08:38

 

Hugo

Пользователь

Сообщений: 23100
Регистрация: 22.12.2012

Но если брать второй результат деления — нужно сперва проверить что есть на что делить!

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

#7

22.09.2020 12:17:46

Цитата
Юрий М написал:
Предложите новое — модераторы поменяют.

Извините, я не знаю, как иначе назвать это…

Цитата
New написал:
P.S. Вернуть текст комментария без автора комментария

Спасибо Вам огромное!

Can’t get it, don’t need it.

 

Юрий М

Модератор

Сообщений: 60335
Регистрация: 14.09.2012

Контакты см. в профиле

#8

22.09.2020 12:27:36

Цитата
Kate написал:
Извините, я не знаю, как иначе назвать это…

Вы не знаете, в чём заключается Ваша задача?  А последнее предложение в стартовом сообщении Вы сами писали?
Мзменил название…

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

#9

22.09.2020 12:31:51

Цитата
Hugo написал:
Но если брать второй результат деления — нужно сперва проверить что есть на что делить!

Поэтому я split сразу отбросила. Спасибо Вам тоже!

Can’t get it, don’t need it.

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

#10

22.09.2020 12:44:14

Цитата
Юрий М написал:
Вы не знаете, в чём заключается Ваша задача?  

Конечно, я знаю, поэтому и описала, как смогла. Откуда мне знать, как Вы хотели, чтобы я ее описала. :)  

Can’t get it, don’t need it.

 

RAN

Пользователь

Сообщений: 7081
Регистрация: 21.12.2012

#11

22.09.2020 12:47:04

Цитата
Kate написал:
VBA editor ругается Compile Error Expected: list separator or )

Это только для вас наличие пробелов не существенно. Но не для VBA.

Код
.Cells(i, 3).Value = Replace(com.Text, com.Author & ":", "")

Изменено: RAN22.09.2020 12:48:22

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

:( Да, Вы правы! Грубая ошибка. Спасибо большое.

Can’t get it, don’t need it.

 

RAN

Пользователь

Сообщений: 7081
Регистрация: 21.12.2012

#13

22.09.2020 13:03:58

Кстати, судя по тому, что у вас после двоеточия стоит пробел, вы пытались написать это

Код
.Cells(i, 3).Value = Replace(com.Text, com.Author & ":" & Chr(10), "")
 

Юрий М

Модератор

Сообщений: 60335
Регистрация: 14.09.2012

Контакты см. в профиле

#14

22.09.2020 13:14:49

Цитата
Kate написал:
Откуда мне знать, как Вы хотели, чтобы я ее описала.

Да не нужно думать, понравится МНЕ или нет. Нужно формулировать так, чтобы из названия ВСЕМ была понятна проблема (задача). И в правилах об этом написано специально.
Ведь смогли же сформулировать в описании — почему бы прямо эту строку не поставить в название? Или Вы полагаете, что название Комментарий VBA — достаточно информативно?
И хватит спорить! Просто примите к сведению и в следующий раз думайте, когда создаёте тему.

 

Kate

Пользователь

Сообщений: 15
Регистрация: 22.09.2020

#15

14.10.2020 22:47:59

RAN, да!  *facepalm* :D потому что я не догнала сразу, что это line feed, а не space.
Еще раз премного благодарна.  

Can’t get it, don’t need it.

  1. 04-03-2017, 05:01 PM


    #1

    drummo2a is offline


    Registered User


    MsgBox compile syntax error or Expected: list separator or )

    I have a simple, I thought, piece of code to check whether recently pasted cells have red font or not.

    It was working well until I tried to add an error check to alert me that no cells were red.

    Here is the code. The variable NoRed is properly defined up at the top.
    After I paste in my text I move things around then check to see if any of 5 cells have red font.

    The MsgBox line keeps giving me either a syntax error (in its current state) or Expected: List separator or ) (if I try to add a title or anything to the msgbox)

    If ActiveCell.Offset(-10, 0).Font.Color = vbRed Then
    ActiveCell.Value = «A»
    GoTo STOPCOUNT
    ElseIf ActiveCell.Offset(-9, 0).Font.Color = vbRed Then
    ActiveCell.Value = «B»
    GoTo STOPCOUNT
    ElseIf ActiveCell.Offset(-8, 0).Font.Color = vbRed Then
    ActiveCell.Value = «C»
    GoTo STOPCOUNT
    ElseIf ActiveCell.Offset(-7, 0).Font.Color = vbRed Then
    ActiveCell.Value = «D»
    GoTo STOPCOUNT
    ElseIf ActiveCell.Offset(-6, 0).Font.Color = vbRed Then
    ActiveCell.Value = «E»
    GoTo STOPCOUNT

    Elseif NoRed = MsgBox (�No Red cells would you like to continue�?�,vbQuestion + vbYesNo)= vbNo Then
    Exit Sub
    End If


  2. 04-03-2017, 07:43 PM


    #2

    ferday is offline


    Registered User


    Re: MsgBox compile syntax error or Expected: list separator or )

    please use code tags, that’s hard to read

    your ElseIf NoRed statement makes no sense. how did you define NoRed?


  3. 04-03-2017, 09:49 PM


    #3

    drummo2a is offline


    Registered User


    Re: MsgBox compile syntax error or Expected: list separator or )

    Sorry, I am new to this, I don’t even know what you mean by code tags.

    The NoRed was defined earlier in the code (Dim NoRed as Integer).
    This is the first mention of NoRed or msgbox in the code. The previous stuff, which I did not show, is just fancy cut and past to move the pasted text into the right cells. I then test it for red font. That is where I am having my difficulties. Any help would be appreciated.

    I should add, I tried it without the NoRed and get the same error

    Elseif MsgBox (“No Red cells would you like to continue…?”,vbQuestion + vbYesNo,)= vbNo Then

    Drummo2a

    Last edited by drummo2a; 04-03-2017 at 09:53 PM.


  4. 04-04-2017, 02:12 AM


    #4

    Re: MsgBox compile syntax error or Expected: list separator or )

    Hi,

    You have smart quotes in that code- you need regular ones- and remove the trailing comma

    Don
    Please remember to mark your thread ‘Solved’ when appropriate.


  5. 04-05-2017, 02:11 PM


    #5

    drummo2a is offline


    Registered User


    Re: MsgBox compile syntax error or Expected: list separator or )

    Thanks, I pasted your line of code in and it worked great. Now I have a more questions. Where do the «smart quotes» come from? How can I tell I have them?


  6. 04-07-2017, 01:24 AM


    #6

    Re: MsgBox compile syntax error or Expected: list separator or )

    They sometimes appear if you copy code from a web site or if your code is pasted from Word.


0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Lisp ошибка лишняя закрывающая скобка на входе
  • Lion alcolmeter sd 400 ошибка e bl