Object两个as-near-as-I-can-tell有效对象的必需错误

时间:2016-12-07 19:35:15

标签: vba excel-vba excel

任何人都可以帮我弄清楚为什么我在这段代码上得到一个对象需要的错误?有问题的一行是

comnum(a) = comnum(a)+1  

我使用msgbox来确保这两件事实际上都有效,并且它们很好地吐出来。但是由于我不知道的原因,虽然vba很乐意单独宣读这两个,但设置它们是一个问题?

为了节省空间,我删除了一些不与此行交互的代码,希望没有人介意:

Sub create_sheets(mms, dds, yys, mme, dde, yye)

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim fso As New FileSystemObject
Dim wb1 As Workbook
Dim wb2 As Workbook

Set wb1 = ThisWorkbook

dd = dds
mm = mms
yyyy = yys

'this is where all that unrelated crap went
'it's just formatting, checking if a filepath exists, and if it does_
'opening the file and copying the data.  
'It's like 60 unrelated lines, hence my omission

Dim comcol As New Collection
Dim comnum As New Collection

            While wb1.Sheets(1).Cells(1, 4) <> ""                               'as long as data remains
            strnum = 0                                                          'start with no counts of the string
            stro = wb1.Sheets(1).Cells(1, 4)                                    'the string is the contents of the first row's string column
            comcol.Add (wb1.Sheets(1).Cells(1, 5))
            comnum.Add (0)

                For c = 1 To 65536                                              'for all rows
                    If wb1.Sheets(1).Cells(c, 4) = stro Then                    'if you see the string
                        strnum = strnum + 1                                     'count it
                        For a = 1 To comcol.Count                               'go through the entire collection
                            If comcol(a) = wb1.Sheets(1).Cells(c, 5) Then       'if it finds the string, increments the count of it
                                MsgBox comnum(a) & " and " & comnum(a) + 1
                                comnum(a) = comnum(a) + 1
                            End If
                        Next a
                        wb1.Sheets(1).Row(c).Delete
                        c = c - 1
                    End If
                Next c

                Sheets("Results").Activate

                Cells(3, 2) = Sheets(1).Cells(1, 4)
                While comcol.Count <> 0
                    Cells(4, 2) = comcol(1) & ", appeared " & comcol(2) & "times"
                Wend
            Wend

提前致谢!

1 个答案:

答案 0 :(得分:1)

您无法更新存储在Key中的值。 你想做那样的事吗

comnum.Add comnum(a) + 1

查看我的评论