2016-11-21 34 views
-1

我在清理一塊VBA時遇到了424錯誤。我沒有寫出所有這些,但似乎沒有任何理由讓這個錯誤出現。它的Excel的Mac所以當然不會切換斷點我 :( 任何想法將是非常有益無理由退回424錯誤

Sub Transform() 

Dim ws As Worksheet 
Dim i, j As Long 
Dim fndList, rpcList, endlist As Variant 
Dim LastRow As Long 
Dim c As Range 

Application.ScreenUpdating = False 

fndList = Array("1","2","3") 
endlist = Array("x","y","z") 
rpcList = Array("a","b","c") 

Set ws = ActiveWorkbook.Sheets("Sheet2") 

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

With ws 

Rows("1:1").Select 
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
Rows("2:2").Select 
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
Rows(1).Delete 
Columns(2).EntireColumn.Delete 

.Range("A1:P1") = endlist 
.Range("A2:P2") = rpcList 



For Each c In .Range("A4:A" & LastRow) 
    ActiveCell.Hyperlinks.Add Anchor:=cell, Address:="https://" & cell.Value 
Next c 


For Each c In .Range("B4:B" & LastRow) 
    ActiveCell.NumberFormat = "[$-409]d-mmm-yy;@" 
Next c 


For Each c In .Range("C4:C" & LastRow) 
    ActiveCell.NumberFormat = "[$-409]d-mmm-yy;@" 
Next c 


For Each c In .Range("G4:G" & LastRow) 
    ActiveCell.Hyperlinks.Add Anchor:=cell, Address:="https://tool" & cell.Value 
Next c 

Dim l As Integer 
Dim larray(1 To 10) As Integer 
Dim k As Integer 
k = 1 

For l = 3 To 600 
If Cells(l, 2).Value > Cells(l, 3).Value Then 
    Cells(l, 2).ClearContents 
    Cells(l, 3).ClearContents 

End If 
Next l 

Dim h As Integer 
h = 1 

Dim m As Integer 
For m = 3 To 600 
If Cells(m, 2) > Now() Then 
    Cells(m, 2).ClearContents 
    End If 

If Cells(m, 3) > Now() Then 
    Cells(m, 3).ClearContents 
    End If 
Next m 

End With 
End Sub 
+3

你有'ws'但是下面的'行()'沒有前導期,所以默認情況下它們會引用ActiveSheet –

回答

3

For Each控制c,但使用的是cell作爲超鏈接參數更改c。到cell

ActiveCell.Hyperlinks.Add錨:=電池,地址:= 「https://開頭」 & cell.Value

For Each cell In .Range("A4:A" & LastRow) 
     cell.Hyperlinks.Add Anchor:=cell , Address:="https://" & cell.Value 
    Next cell 

    .Range("B4:C" & LastRow).NumberFormat = "[$-409]d-mmm-yy;@" 

    For Each cell In .Range("G4:G" & LastRow) 
     cell.Hyperlinks.Add Anchor:=cell, Address:="https://tool" & cell.Value 
    Next cell 
+1

但是你不能添加多個超鏈接到同一個單元?我不清楚OP在這裏要做什麼。 –

+0

@TimWilliams謝謝。我忘記了這一點,因爲當我寫vbscript時,我在「Next」後停止添加控件。 – 2016-11-21 23:56:44

+0

'ActiveSheet.Hyperlinks.Add'? –