2016-08-16 74 views
0

我無法弄清我們爲什麼會收到錯誤'9'。我聲明瞭字符串數組,然後我想使用數組值來設置表名。我做錯了什麼?通過字符串數組循環,錯誤'9'

Dim wsText() As String 
Dim sht As Worksheet 
Dim wSum As Worksheet 
Dim service As String 
Dim supplier As String 
Dim priceRange As String 
Dim price As String 
Dim Lrow As Integer, LastRow As Integer 

Set sht = ThisWorkbook.Worksheets(4) 
Set wSum = ThisWorkbook.Worksheets(Summary) 

wsText = Array("<25K", "25K <100K", "100K <250K", "250K <500K", "500K <1M", "1M <5M", "5M <15M", "15M <30M", "30M <50M") 

LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 

    For Each element In wsText 
     For i = 5 To LastRow 
      For j = 13 To 47 

       Lrow = wSum.UsedRange.Rows(wSum.UsedRange.Rows.Count).Row + 1 

       service = ThisWorkbook.Worksheets(element.Value).Cells(i, 1).Text 
       supplier = ThisWorkbook.Worksheets(element.Value).Cells(4, j).Text 
       priceRange = ThisWorkbook.Worksheets(element.Value).Cells(2, 1).Text 
       price = ThisWorkbook.Worksheets(element.Value).Cells(i, j).Text 

       wSum.Cells(Lrow, 1) = service 
       wSum.Cells(Lrow, 2) = supplier 
       wSum.Cells(Lrow, 3) = priceRange 
       wSum.Cells(Lrow, 4) = price 
      Next j 
     Next i 
    Next element 


End Sub 

回答

2

對於初學者這部分是錯誤的ThisWorkbook.Worksheets(Summary)這裏總結作爲變量,但不能看到你的代碼分配給它。這將拋出錯誤9.如果工作表名稱本身是摘要,那麼在雙引號內使用它,如ThisWorkbook.Worksheets("Summary")

+1

++打我吧:)刪除了我發表 –

+0

感謝一噸....一些成就.... :) – cyboashu

+1

非常感謝你!我恨我的自我,我不能仔細查看代碼! –