Riufaan
Riufaan

Reputation: 43

Code gives me Compile Error, Expected: List Separator or )

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:\Users\athif\Desktop\Test_Pos\DataBase.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:\Users\athif\Desktop\Test_Pos\DataBase.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

Upvotes: 1

Views: 62322

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149305

There are lot of errors with that line

  1. You are using . You need to use "
  2. Workbooks do not have the .SaveAs property

If you are trying to save the current workbook then do this

Dim myData As Workbook

Set myData = ThisWorkbook
myData.SaveAs Filename:="C:\Users\athif\Desktop\Test_Pos\DataBase.xlsx", FileFormat:=51

For file formats, you may want to see THIS Link.

Upvotes: 8

Related Questions