Sub nationalityscript()
Dim i As Integer
Dim temp As Integer
Dim Country As String
Dim strEnd As Integer
Dim strComplete As String
i = 0
Do While i < 300
Dim k As Integer
Dim a As String
strComplete = Cells(h, i).Value
strEnd = Len(strComplete)
k = 0
Do While k < strEnd
a = Cells(h, i).Value.Substring(k, k)
If a = "," Then
temp = a
End If
k = k + 1
Loop
Country = Cells(h, i).Value.Substring(temp, strEnd)
i = i + 1
Loop
End Sub
嗨,這是我第一天使用vba進行編程,所以請對我輕鬆點。從單元格讀取字符串時出錯
我正在寫excel中的宏,專注於列h。在列h中找到的任何字符串代碼都會通過,在最後一個「,」後面標識字符串的最後一部分,然後用該字符串替換該單元格中的字符串。
我認爲這可能與我的問題無關,因爲我的問題是將單元格中的字符串分配給一個新變量。
我正的錯誤是:
運行-錯誤1004,對象定義或應用程序定義的錯誤。
請下次使用相應的標籤。 VB.NET不是VBA – Steve
@Bjørn-RogerKringsjå-我很好奇你將如何使用Web搜索引擎來找到OP的答案。你能舉一個例子嗎? – Davesexcel
@Davesexcel我懷疑插入錯誤信息會導致很多提及'Option Explicit'的命中。 – pnuts