0
我創建了一個存儲工作表名稱及其編號的字典。從VBA中的DICTIONARY中提取項目
因此,代碼是:
Sub SetDiction()
Dim num as Excel.Range
Dim wks As Excel.Worksheet
For each wks in ThisWorkbook.Worksheets
Set num = Nothing
Set num = wks.Range("SheetNumber")
If not(num is Nothing) Then
rModule.rDictionary.Add:=num.Value Item:=wks
End If
下一頁 末次
現在試圖讓周的名字,並把它在另一個worksheet.The代碼:
Sub GetSheet()
Dim key as variant
For each key in rModule.rDictionary.Keys
With Sheet2
.Cells(2,1).Value = rModule.rDictionary.Item(key)
End With
End Sub
它給我的應用程序定義或對象定義的錯誤。 有人可以幫忙嗎?
num是一個excel範圍。我需要將該鍵作爲從「SheetNumber」範圍提取的sheetnumber並添加爲字典的鍵。作爲與這個鍵相對應的項目,我希望工作表名稱對應於該工作表編號。 – Naina
將wks.Name作爲字符串添加名稱 –
Alex正試圖使用代碼將此名稱分配給工作表:set sht.Name = rModule.rDictionary(key)。將錯誤顯示爲對象或未定義塊變量。你能告訴我我哪裏錯了嗎? – Naina