|
点击常驻入职按钮之后,work flow里的信息会按照格式copy过来,我设置的是每列为一个数组的单位传值,当work flow里面的数据在两条以上时可以正常传值,但是当数据只有一条时,传值失败,系统提示为类型不匹配,请问是什么原因呢?代码如下:
Sub test1()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim arr1 As Variant
Dim arr2 As Variant
Dim arr3 As Variant
Dim arr4 As Variant
Dim arr5 As Variant
Dim p&, i&
Dim w&, r&, r1&, k&
Set ws1 = Worksheets("workflow")
Set ws2 = Worksheets("card list")
p = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
i = ws2.Cells(ws2.Rows.Count, 4).End(xlUp).Row + 1
arr1 = ws1.Range(ws1.Cells(3, 1), ws1.Cells(p, 1)).Value
ws2.Range("d" & i).Resize(UBound(arr1)) = arr1
arr2 = ws1.Range(ws1.Cells(3, "C"), ws1.Cells(p, "C")).Value
ws2.Range("a" & i).Resize(UBound(arr2)) = arr2
arr3 = ws1.Range(ws1.Cells(3, "G"), ws1.Cells(p, "G")).Value
ws2.Range("b" & i).Resize(UBound(arr3)) = arr3
arr4 = ws1.Range(ws1.Cells(3, "I"), ws1.Cells(p, "I")).Value
ws2.Range("c" & i).Resize(UBound(arr4)) = arr4
arr5 = ws1.Range(ws1.Cells(3, "F"), ws1.Cells(p, "F")).Value
ws2.Range("J" & i).Resize(UBound(arr5)) = arr5
w = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
For r1 = 3 To w
r = ws2.Cells(Rows.Count, 11).End(xlUp).Row + 1
ws2.Cells(r, "K").Value = Now()
If Mid(ws1.Cells(r1, "B").Value, 1, 1) = "W" Then
ws2.Cells(r, "H").Value = ws1.Cells(r1, "B").Value
Else
ws2.Cells(r, "F").Value = ws1.Cells(r1, "B").Value
End If
Next
End Sub
|
|