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 FunctionThank you in advance!
-
Edited by
Friday, May 26, 2017 10:26 PM
-
Edited by
Answers
-
Function ABCDEFG(Number1 As Integer, Name1 As String)
….
Select Case Number1
Case 79001Hi 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 Functionas this function defaults False as result.
Imb.
-
Marked as answer by
KateStsv
Saturday, May 27, 2017 10:38 PM
-
Marked as answer by
-
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
-
Marked as answer by
-
#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 |
#1 22.09.2020 11:34:55 Уважаемые корифеи VBA, прошу помощи! Имеется макрос, который собирает все комментарии (заметики, notes в Excel 365) в таблицу на отдельном листе. При создании комментария в его шапке автоматически появляется имя автора комментария с двоеточием (см. изображение). При попытке просто «склеить» автора с символом двоеточия VBA Editor выдает ошибку Compile Error Expected: list separator or )
Как правильно удалить имя автора и двоеточие, оставив только сам текст комментария? Спасибо. Прикрепленные файлы
Can’t get it, don’t need it. |
||
|
Юрий М Модератор Сообщений: 60335 Контакты см. в профиле |
Kate, из сузествующего названия темы можно понять задачу? Предложите новое — модераторы поменяют. |
|
New Пользователь Сообщений: 4394 |
#3 22.09.2020 11:56:51 Тема: Вернуть текст комментария без автора комментария Вариант 1
Вариант 2
Изменено: New — 22.09.2020 12:12:32 |
||||
|
Hugo Пользователь Сообщений: 23100 |
А можно брать split(text,»:»,2)(1) |
|
New Пользователь Сообщений: 4394 |
кстати, да… спасибо, Игорь. Добавил 2-й вариант в свой ответ Изменено: New — 22.09.2020 12:08:38 |
|
Hugo Пользователь Сообщений: 23100 |
Но если брать второй результат деления — нужно сперва проверить что есть на что делить! |
|
Kate Пользователь Сообщений: 15 |
#7 22.09.2020 12:17:46
Извините, я не знаю, как иначе назвать это…
Спасибо Вам огромное! Can’t get it, don’t need it. |
||||
|
Юрий М Модератор Сообщений: 60335 Контакты см. в профиле |
#8 22.09.2020 12:27:36
Вы не знаете, в чём заключается Ваша задача? А последнее предложение в стартовом сообщении Вы сами писали? |
||
|
Kate Пользователь Сообщений: 15 |
#9 22.09.2020 12:31:51
Поэтому я split сразу отбросила. Спасибо Вам тоже! Can’t get it, don’t need it. |
||
|
Kate Пользователь Сообщений: 15 |
#10 22.09.2020 12:44:14
Конечно, я знаю, поэтому и описала, как смогла. Откуда мне знать, как Вы хотели, чтобы я ее описала. Can’t get it, don’t need it. |
||
|
RAN Пользователь Сообщений: 7081 |
#11 22.09.2020 12:47:04
Это только для вас наличие пробелов не существенно. Но не для VBA.
Изменено: RAN — 22.09.2020 12:48:22 |
||||
|
Kate Пользователь Сообщений: 15 |
Can’t get it, don’t need it. |
|
RAN Пользователь Сообщений: 7081 |
#13 22.09.2020 13:03:58 Кстати, судя по тому, что у вас после двоеточия стоит пробел, вы пытались написать это
|
||
|
Юрий М Модератор Сообщений: 60335 Контакты см. в профиле |
#14 22.09.2020 13:14:49
Да не нужно думать, понравится МНЕ или нет. Нужно формулировать так, чтобы из названия ВСЕМ была понятна проблема (задача). И в правилах об этом написано специально. |
||
|
Kate Пользователь Сообщений: 15 |
#15 14.10.2020 22:47:59 RAN, да! *facepalm* Can’t get it, don’t need it. |
-
04-03-2017, 05:01 PM
#1

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 STOPCOUNTElseif NoRed = MsgBox (�No Red cells would you like to continue�?�,vbQuestion + vbYesNo)= vbNo Then
Exit Sub
End If
-
04-03-2017, 07:43 PM
#2

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?
-
04-03-2017, 09:49 PM
#3

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.
-
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.
-
04-05-2017, 02:11 PM
#5

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?
-
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.