0
我有以下代碼。我調試了一下,發現問題出在for內部的IF上。在VBA腳本中獲取錯誤438
確切的錯誤是:運行時錯誤438 - 對象不支持此屬性或方法
任何線索可能是什麼? 我感謝任何幫助。 謝謝!
Sub dimensiones()
Dim Hoja1 As Object
Dim Hoja2 As Object
Set Hoja1 = Worksheets("INPUT")
Set Hoja2 = Worksheets("OUTPUT")
Dim inicio_filas As Integer
Dim col_s1 As Integer
Dim col_s2 As Integer
Dim limite_filas As Integer
Dim m As Integer
col_s1 = 38
col_s2 = col_s1 + 2
inicio_filas = 3
limite_filas = 1000
Dim k As Integer
k = inicio_filas
For i = inicio_filas To limite_filas
For m = 1 To col_s2 - 1
Hoja2.Cells(k, m) = Hoja1.Cells(i, m)
Next m
k = k + 1
If Hoja1(i, col_s2) <> "" Then
For m = 1 To col_s1 - 1
Hoja2.Cells(k, m) = Hoja1.Cells(i, m)
Next m
Hoja2.Cells(k, col_s2) = Hoja1.Cells(i, col_s2)
Hoja2.Cells(k, col_s2 + 1) = Hoja1.Cells(i, col_s2 + 1)
Hoja2.Cells(k, col_s2 + 2) = Hoja1.Cells(i, col_s2 + 2)
k = k + 1
End If
Next i
End Sub
它停在哪裏? – Sam
不要說了,但是當我刪除For中的整個IF時,它會執行完整的代碼。我測試了刪除除了k = k + 1之外的所有IF,並且我得到了同樣的錯誤。感謝您的回覆。 –
我建議'Dim Hoja1 As Worksheet'而不是'Dim Hoja1 As Object'。它使您的代碼更易於閱讀。 – FreeMan