【发布时间】:2015-04-19 00:00:51
【问题描述】:
有人帮我编写了初始代码,我试图修改它,但它错了。
我需要将电子表格中的工作表 2 与工作表 4 到 10 进行比较,并且如果 e 行或 b 行的值与任何其他行都不匹配。将整行复制到工作表 1 的底部。
这是我目前所拥有的,但该值并未设置为 true,它会在每张纸之后打印。我坚持
Sub Button13() 'merge
Dim lastSourceRow As Long, LastTargetRow As Long, allSheets As Long, lastSheet As Long
Dim source As String, TARGET As Integer
Dim tempVal As String, tempValE, tempValT
Dim tRow As Long, lRow As Long, lCol As Long, nRow As Long
Dim match As Boolean
source = "Sheet2"
lastSheet = "10"
lastSourceRow = Sheets(source).Range("A" & Rows.Count).End(xlUp).Row
For allSheets = 1 To lastSheet
TARGET = allSheets
LastTargetRow = Sheets(TARGET).Range("A" & Rows.Count).End(xlUp).Row
For lRow = 2 To lastSourceRow 'Loop through Rows on currentsheet
Count = "0"
match = False 'Reset boolean test for each new row
tempVal = Sheets(source).Cells(lRow, "B").Value 'Assign the tempValue to compare
tempValE = Sheets(source).Cells(lRow, "E").Value
For tRow = 2 To LastTargetRow 'Loop through entire target sheet
tempValT = Sheets(TARGET).Cells(tRow, "B").Value
If (allSheets <> 2 Or allSheets <> 3) And tempVal = Sheets(TARGET).Cells(tRow, "B").Value And tempValE = Sheets(TARGET).Cells(tRow, "E").Value Then
match = True
ElseIf (allSheets <> 2 Or allSheets <> 3) And tempVal = Sheets(TARGET).Cells(tRow, "B").Value And tempValE = "" Then
match = True
ElseIf (allSheets <> 2 Or allSheets <> 3) And tempVal = Sheets(TARGET).Cells(tRow, "B").Value Then
match = True
'ElseIf Sheets(TARGET).Cells(tRow, "G").Value < DateAdd("m", -5, Date) Then
'match = True
End If
Next tRow
If match = False Then 'No Match found, copy row
nRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row + 1
For lCol = 1 To 26 'Copy entire row by looping through 6 columns
Sheets("Sheet1").Cells(nRow, lCol).Value = Sheets(source).Cells(lRow, lCol).Value
Next lCol
End If
Next lRow
Next allSheets
End Sub
【问题讨论】:
-
如果对您有帮助,请随时将我的答案标记为您的解决方案