我已搜索但似乎无法弄清楚如何在我找到我的副本的旁边的列中打印指定的值。我之前所拥有的是首先指定不同范围的代码,然后查看是否在工作表X中的工作表Y中找到重复。工作表Le是本周信息和工作表Be是最后几周的信息。
如果我发现指定范围内的副本,我希望在我的交货单上打印副本旁边的A列中的已交付或未交付,具体取决于我的函数compareAEO的输出是打印是真还是假。
我正在寻找的条件是,如果我们可以在工作表(Be)上的工作表(Le)中找到B列中的相同值,那么它将检查F列中的文本是否已更改。如果是,那么它将在工作表(Le)=已交付的A列中打印。否则不交付。
然后检查是否M列中的日期相同。如果没有那么它将打印在表(Le)的A栏中重新计划。
不久 列B中单元格的IF值,Sheet(Le)= B列中的值,Sheet(Be) 工作表上的A列中的值Le ="已交付"否则"没有交付"。
然后
如果列M中的单元格中的值,则片材(Le)<>如果列M中的单元格中的值,则表单(Be)中的值列为A,Sheet(Le)="重新计划"
这就是我的数据的样子, 表(Le)
Col B Col F Col M
PZ2408 X13 2017-02-13
PZ2345 X30 2017-02-23
PZ2463 X45 2017-02-25
PZ2513 X13 2017-02-10
PZ2533 X70 2017-02-05
PZ2561 X60 2017-02-20
对于工作表(Be),我的数据看起来像这样
Col B Col F Col M
PZ2408 X30 2017-02-13
PZ2345 X30 2017-02-23
PZ2463 X30 2017-02-25
PZ2513 X13 2017-02-05
PZ2533 X13 2017-02-10
PZ2561 X60 2017-02-17
代码完成后,我希望它显示为例如
Sheet(Le)
col A Col B Col F Col M
Delivered PZ2408 X13 2017-02-13
Not Delivered PZ2345 X30 2017-02-23
Delivered PZ2463 X45 2017-02-25
replanned PZ2513 X13 2017-02-10
Delivered PZ2533 X70 2017-02-05
replanned PZ2561 X60 2017-02-20
笨拙我的未交付,交付和重新计划的陈述不起作用,我的大脑不起作用。
可以帮助我节省一天的时间吗?
Sub checkASMT()
Dim rng1 As Range
Dim rng2 As Range
Dim lastRowSource As Long
Dim lastRowTarget As Long
Dim row As Long
Dim ASMT As String
'Looping trough Range
With ThisWorkbook.Worksheets("Le")
lastRowTarget = .Range("B" & .Rows.Count).End(xlUp).row
For i = 29 To lastRowTarget
ASMT = .Range("b" & i).value
'Define range and see if we can find duplicates
With ThisWorkbook.Worksheets("Be")
lastRowSource = .Range("B" & .Rows.Count).End(xlUp).row
Set rng1 = .Range("B3", "B" & lastRowSource)
row = findValueInRangeReturnRow(rng1, ASMT)
'Check FAX
If compareAEO(i, row, "FAX") = True Then
'Debug.Print compareASMT(i, row, "FAX")
Worksheets("Le").Cells(i, ASMT).value = "Not Delivered"
Else
.Worksheets("Le").Cells(i, ASMT).value = "delivered"
'Check if dax are correct
If compareAEO(i, row, "DAX") = False Then
.Worksheets("Le").ASMT.Offset(0, 1).value = "Replan"
End If
End With
Next i
End With
End Sub
这是我的第一个功能
Function findValueInRangeReturnRow(rng As Range, value As Variant) As Long
Set c = rng.Find(value, LookIn:=xlValues)
If Not c Is Nothing Then
findValueInRangeReturnRow = c.row
End If
End Function
我的第二个函数,用于检查是否在指定范围内找到重复项。
Function compareAEO(rad1 As Variant, rad2 As Variant, typeCOMPARE As String) As Boolean
Dim col1 As String
Dim col2 As String
Select Case typeCOMPARE
Case "FAX"
col1 = "F"
col2 = "F"
Case "DAX"
col1 = "M"
col2 = "M"
End Select
If ThisWorkbook.Worksheets("Le").Range(col1 & rad1).value = ThisWorkbook.Worksheets("Be").Range(col2 & rad2).value Then
compareAEO = True
Else
compareAEO = False
End If
End Function
答案 0 :(得分:1)
您在每个循环中获得了两个页面的最后一行。只需要在循环外的顶部获取它们一次。对于您设置的范围也是如此。你可以看到我把它们放在循环之前的顶部。
我真的不知道你在使用ASMT的是什么。看起来你试图将它用作某些编码中的范围而不是范围(" B"& I)。我在" B"中使用了字符串。 Le的列与" B"当我测试时,Be的列。
它对我有用。您必须根据自己的需要进行更改。你不需要所有的功能,他们所完成的都在这个子程序中。
Sub checkASMT()
Dim rng1 As Range
Dim rng2 As Range
Dim lastRowLE As Long
Dim lastRowBe As Long
Dim row As Long
Dim ASMT As String
Dim LEws As Worksheet
Dim tmpRng As Range
Set LEws = Worksheets("Le")
lastRowLE = Sheets("Le").Cells(ActiveSheet.Rows.Count, "B").End(xlUp).row
lastRowBe = Sheets("Be").Cells(ActiveSheet.Rows.Count, "B").End(xlUp).row
Set rng1 = Sheets("Be").Range("B3", "B" & lastRowBe)
For i = 29 To lastRowLE
Set tmpRng = Sheets("Le").Range("b" & i)
ASMT = tmpRng.Value
Set c = rng1.Find(ASMT, LookIn:=xlValues)
If Not c Is Nothing Then
row = c.row
If ThisWorkbook.Worksheets("Le").Range("F" & i).Value = ThisWorkbook.Worksheets("Be").Range("F" & row).Value Then
' Worksheets("Le").Cells(i, ASMT).Value = "Not Delivered"
' Did you intend to use ASMT as the column number?
' I'm going to hard code that as column 27 for my purposes. You can change it if you need to
LEws.Cells(i, 27).Value = "Not Delivered" ' column 27 is "AA"
Else
LEws.Cells(i, 27).Value = "Delivered"
End If
If ThisWorkbook.Worksheets("Le").Range("M" & i).Value = ThisWorkbook.Worksheets("Be").Range("M" & row).Value Then
' .Worksheets("Le").ASMT.Offset(0, 1).Value = "Replan"
' again I don't understand the reference to ASMT. That is a string value - unless it is a numeric value in the string
' I'm going to assume that you intended for "Replan" to go into column C on row i
Else
LEws.Range("C" & i).Value = "Replan"
End If
End If
Next i
End Sub
答案 1 :(得分:0)
试试这个;将数据放在从B到G的单页中(Le然后是Be);将此公式放在H列中
=IF(VLOOKUP(E2,B$2:D$7,2,FALSE)=F2,IF(G2<D2,"replanned","Not Delivered"),"delivered")
调整此公式以满足您的需求,使其跨表格工作