在这方面,我确实需要很多帮助,因此,如果您能接受我,我将不胜感激。我是VBA的新手,因此在运行代码时遇到了困难。它不断向我返回错误:未设置对象变量。我可以知道代码有什么问题吗?
在此先感谢您的帮助!
Sub sub_input (dicDat as Dictionary)
Dim ws As Worksheet: Set ws =ActiveSheet
Dim i As Integer
Dim j As Integer
Dim vTemp As Variant
Range("rInputStart").Parent.Calculate
vTemp =Range(Range("rInputStart").Offset(1),_
Range("rInputStart").End(xlDown).Offset(0,2)).value
Dim info as string
Dim currency As String: currency = vbNullString
Dim exchangeRate as String: exchangeRate = vbNullString
Dim remark as String: remark = vbNullString
For j =1 To 10
info= "info" & CStr(j)
info = Range("rInfoManual").value
currency= "dl_currency" & CStr(j)
exchangeRate = "exchange" & CStr(j)
Remark = "remarks" & CStr(j)
For i =LBound(vTemp,1)ToUBound(vTemp,1)
If vTemp(i,1)="currency"And dicDat(dl_currency)<> vbNullString _
Then
vTemp(i,3)= currency
Endif
If vTemp(i,2)="remark"Then
vTemp(i,3)=Remark
EndIf
If vTemp(i,2)="exchangeRate"Then
vTemp(i,3)= exchangeRate
EndIf
Next i
Next j
End Sub
当前dicData的定义如下:[但是在Outlook VBA中定义。不确定如何在Excel VBA中调用键]
Private Sub Code1()
Dim dicDat as Dictionary
Set dicDat = New dictionary
dicData.add "info1", item.info
dicData.add "info2", item.info
dicData.add "currency1", item.currency
dicData.add "currency2", item.currency
dicData.add "exchangeRate1", item.rate
dicData.add "exchangeRate2", item.rate
dicData.add "remark1", item.remark
dicData.add "remark2", item.remark
发生的事情是,我继承了一个已使用键info,currency,exchangeRate,remark等正确运行的现有代码。但是,键现在已更改为info(1-10),currency(1-10)等等。我需要修改代码以适应每个键的循环。这样,它就会循环一次,保存,然后移至第二组,依此类推。