应用程序错误,无法链接并将数据放到另一列,需要帮助才能完成代码

时间:2016-10-13 13:15:58

标签: vba excel-vba excel

当我进行单词计数时,创建的新表单,A列单元格中充满了"所有的字#34;并且宏因错误而停止,我需要自动更改列的代码,当私有获取列满时,帮我解决这个问题...意味着应该生成字数和频率的数据很大并且由于数据量大... 。列单元格已满并发生错误....我试图复制并移动新生成的"所有单词"数据,但是没有正常工作..我需要一些技巧代码,自动将所有数据...放入新列...以下是用于字数的代码...........

Sub MakeWordList()
    Dim InputSheet As Worksheet
    Dim WordListSheet As Worksheet
    Dim PuncChars As Variant, x As Variant
    Dim i As Long, r As Long
    Dim txt As String
    Dim wordCnt As Long
    Dim AllWords As Range
    Dim PC As PivotCache
    Dim PT As PivotTable

    Application.ScreenUpdating = False
    Set InputSheet = ActiveSheet
    Set WordListSheet = Worksheets.Add(after:=Worksheets(Sheets.count))
    WordListSheet.Range("A1:B1") = "All Words"
    WordListSheet.Range("A1:B1").Font.Bold = True
    InputSheet.Activate
    wordCnt = 2
    PuncChars = Array(".", ",", ";", ":", "'", "!", "#", "-", "--", "---", "@", "`", _
       "$", "%", "&", "(", ")", " - ", "_", "--", "+", "<", ">", "BLANK", _
        "=", "~", "/", "\", "{", "}", "[", "]", """", "?", "*", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
            r = 1


'   Loop until blank cell is encountered
    Do While Cells(r, 1) <> ""
'       covert to UPPERCASE
        txt = UCase(Cells(r, 1))
'       Remove punctuation
        For i = 0 To UBound(PuncChars)
            txt = Replace(txt, PuncChars(i), "")
        Next i
'       Remove excess spaces
        txt = WorksheetFunction.Trim(txt)
'       Extract the words
        x = Split(txt)
        For i = 0 To UBound(x)
            WordListSheet.Cells(wordCnt, 1) = x(i)
            wordCnt = wordCnt + 1
        Next i
    r = r + 1
    Loop

'   Create pivot table
    WordListSheet.Activate
    Set AllWords = Range("A1:B1").CurrentRegion
    Set PC = ActiveWorkbook.PivotCaches.Add _
        (SourceType:=xlDatabase, _
        SourceData:=AllWords)
    Set PT = PC.CreatePivotTable _
        (TableDestination:=Range("D1"), _
        TableName:="PivotTable1")
    With PT
        .AddDataField .PivotFields("All Words")
        .PivotFields("All Words").Orientation = xlRowField
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

声明另一个变量:

    OutClm = 1
    For i = 0 To UBound(x)
        if wordCnt > WordListSheet.Rows.Count Then
            OutClm = OutClm + 1
            wordcnt = 1
        End If
        WordListSheet.Cells(wordCnt, OutClm) = x(i)
        wordCnt = wordCnt + 1
    Next i

然后改变你的循环:

EntityA {
    (...)
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "entityA")
    private List<EntityB> listOfBs; 
    (...)
    // getters and setters
}

EntityB {
    (...)
    @ManyToOne
    @JoinColumn(name = "idEntityA)
    private EntityA entityA; 
    (...)
    // getters and setters
}