简单的vba sub给出错误编译错误:预期:=

时间:2018-01-12 13:49:44

标签: excel vba

我在excel vba中有一个非常简单的子:

updatedDbList2

我只想提供列号和行号以对齐文本。我也尝试使用完整的工作表引用来完成单元格的完整路径,但这没有帮助。

当我尝试使用sub时:

List<FinalObject> finalList = new ArrayList<>();

//Step 1: Extract many to one relations
//assuming dbList is sorted according to dbUserId, if not perform dbList.sort() with custom comparator
List<ObjectFromDb> updatedDbList1 = new ArrayList<>();
ArrayList<Long> apiUserIDs = new ArrayList<Long>();
Long currentdbUserID = -1L;
for(int i=0; i < dbList.size(); i++) {
    if(dbList.get(i).dbUserId != currentdbUserID) {
        if(apiUserIDs.size() >= 2) {
            ArrayList<Long> dbUserIDs = new ArrayList<Long>();
            dbUserIDs.add(currentdbUserID);
            finalList.add(new FinalObject(dbUserIDs, apiUserIDs));
        }
        if(i==dbList.size()-1 || dbList.get(i).dbUserId != dbList.get(i+1).dbUserId){
            updatedDbList1.add(dbList.get(i));
        }
        currentdbUserID = dbList.get(i).dbUserId;
        apiUserIDs = new ArrayList<Long>();
    }
    apiUserIDs.add(dbList.get(i).apiUserId);
}

//Step 2: Extract one to many relations
//assuming dbList is sorted according to apiUserId, if not perform dbList.sort() with custom comparator
List<ObjectFromDb> updatedDbList2 = new ArrayList<>();
ArrayList<Long> dbUserIDs = new ArrayList<Long>();
Long currentApiUserID = -1L;
for(int i=0; i < updatedDbList1.size(); i++) {
    if(updatedDbList1.get(i).apiUserId != currentApiUserID) {
        if(dbUserIDs.size() >= 2) {
            apiUserIDs = new ArrayList<Long>();
            apiUserIDs.add(currentApiUserID);
            finalList.add(new FinalObject(dbUserIDs, apiUserIDs));
        }
        if(i==updatedDbList1.size()-1 || updatedDbList1.get(i).apiUserId != updatedDbList1.get(i+1).apiUserId){
            updatedDbList2.add(updatedDbList1.get(i));
        }
        currentApiUserID = updatedDbList1.get(i).apiUserId;
        dbUserIDs = new ArrayList<Long>();
    }
    dbUserIDs.add(updatedDbList1.get(i).dbUserId);
}

//Step 3: Extract one to one relations
for(int i=0; i < updatedDbList2.size(); i++) {
    dbUserIDs = new ArrayList<Long>();
    dbUserIDs.add(updatedDbList2.get(i).dbUserId);
    apiUserIDs = new ArrayList<Long>();
    apiUserIDs.add(updatedDbList2.get(i).apiUserId);
    finalList.add(new FinalObject(dbUserIDs, apiUserIDs));
}

例如,我收到错误:

Private Sub AlignText(r As Integer, c As Integer)                                                 'A sub to align the data in the cell
With ActiveSheet
    .Cells(r, c).HorizontalAlignment = xlCenter
    .Cells(r, c).VerticalAlignment = xlCenter
End Sub

我之前写过非常相似的潜艇,对齐文本以及做其他事情,他们工作得很好。这一定很简单,但我不知道是什么。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

使用:

transactions <- read.transactions("file.csv", sep=",")
m1<-apriori(transactions, parameter = list(support=0.02, minlen=3))
inspect(sort(m1, by="support"))

注意:您应该尽量避免使用AlignText NextRow, 16 。我也会将ActiveSheet对象添加到您的Worksheet

Sub

并使用以下方式调用它:

Private Sub AlignText(Sht As Worksheet, r As Integer, c As Integer)

'A sub to align the data in the cell
With Sht
    .Cells(r, c).HorizontalAlignment = xlCenter
    .Cells(r, c).VerticalAlignment = xlCenter
End With

End Sub