无故返回424错误

时间:2016-11-21 23:39:28

标签: vba excel-vba excel

我正在清理一块VBA上的424错误。我没有写下所有这些,但似乎没有任何理由让这个错误出现。它对于mac来说非常出色,所以当然它不会为我切换断点 :( 任何想法都会非常有用

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

1 个答案:

答案 0 :(得分:3)

您的For Each控件为c,但您使用cell作为超链接参数。将c更改为cell

  

ActiveCell.Hyperlinks.Add Anchor:= cell,Address:=“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