没有按预期复制值

时间:2019-08-01 13:30:41

标签: excel vba

我需要将编号从所选文件传输到Activeworkbook。但是,如果范围("A19:A30") = "P11,P22,P45_1"的值是活动工作簿中的下一个工作表,而所选工作簿的值是(A20:A45) = "P33,P78,P23_M1"范围中的下一个工作表,则是所选工作簿中的下一个工作表。但是工作表没有按预期进行更改。

wbcopyfrom是选定的工作簿,它有4张纸。如果值是column A = P24,P46_A,P54_MC1并且wbcopyto是我正在运行此代码的activeworkbook,则应该更改。如果column A的值为"P11,P22,P31,P43,P49_FR,P52_FR,P57_MC1",它将更改工作表。使用此功能,应将C中的列DEwbcopyfrom复制到wbcopyto的{​​{1}}像这样…… column C


代码:

VALUE_C + VALUE_D - VALUE_E

For Each wsCopyFrom In wbCopyFrom.Worksheets For Each cell_3 In wsCopyFrom.Range("A20:A45").Cells If cell_3.Value = "P24,P46_A,P54_MC1" Then found = True If found = True Then j = 3 For j = 3 To 6 Set wsCopyFrom = wbCopyFrom.Worksheets(j) Next j End If End If For Each wsCopyTo In wbCopyTo.Worksheets For Each cell_1 In wsCopyTo.Range("A19:A30").Cells If cell_1.Value = "P11,P22,P31,P43,P49_FR,P52_FR,P57_MC1" Then found = True If found = True Then k = 1 For k = 1 To 8 Set wsCopyTo = wbCopyTo.Worksheets(k) Next k End If End If If cell_3.Value = "P11,P22,P31,P43,P49_FR,P52_FR,P57_MC1" Then found = True If found = True Then l = 1 For l = 1 To 8 Set wsCopyTo = wbCopyTo.Worksheets Next l End If End If For i = 20 To 31 Set Cell_to = wsCopyTo.Cells(i - 1, 3) Set cell_from_C = wsCopyFrom.Cells(i, 3) Set cell_from_D = wsCopyFrom.Cells(i, 4) Set cell_from_E = wsCopyFrom.Cells(i, 5) Cell_to.Value = cell_from_C.Value & " +" & cell_from_D.Value & " " & cell_from_E.Value Next i Next cell_1 Next wsCopyTo Next cell_3 Next wsCopyFrom wbcopyfrom的值,但问题是wbcopyto的第一张纸和C19:C30的第一张纸的VALUE_C(C20:C31) + VALUE_D(D20:D31) - VALUE_E(E20:E31) = wbcopyfrom的值wbcopyto仅被填充为与其他7个工作表相同的值。

0 个答案:

没有答案