•读取从2开始的行并获得列d •检查该行的A列,如果它是4610 *,则获取B列的值 •现在通读一行,如果值与上一列相同d检查一列的值 •如果新行的列a等于480 *或490 *,请检查行B的值 •如果新的B列值为= abs(旧的b列值),那就很好。保留这些行 •如果col d仅具有一个值4610 *或480 *或490 *而没有匹配的对应值,则将其删除
希望更好。基本上,我需要在d列中使用唯一编号才能有两个条目 •a列中的值为4610 *且值为负 •另一个480或490,其b列中的值等于4610的绝对值
基本上,这有点像支票簿,只是我完成了数十万笔交易,并在这些工作表中发送。我什至尝试查找VBA来制作支票簿,这就是我摆脱了绝对不需要的所有数据的方式。希望这更有意义。对于每4610个,如果匹配的是480个或490个,我会关心并且需要保留两者,但是如果只有一个或另一个,则不需要该信息
因此,在某些地方,有时是490到490,它们共享一个文档号,但是这两个对我来说并不重要,因此可以删除它们
我正在尝试使用VBA,但是我是一个菜鸟,但是我设法获取了一个非常大的数据集并删除了我绝对不需要的所有行。现在,我正在尝试找出vba代码,该代码将使我完成删除未使用的其余数据的工作。我正在截屏,但基本上在d列中我没有文档。我需要查看所有行,如果a列是4610。*我需要为480 *或490 *的a列中的同一文档编号具有匹配值,并且b 4610 *列的值必须为负,并且对应的480 *和490 *帐户的文档编号必须是该负数的绝对值的=。
如果任何一个文档号。在a列中有4610. *但在a列中没有匹配的480 *或490 *号,那么我需要删除该行。反之亦然,如果在a列中有480 *或490 *,而在d列中没有相同的文档,则在a列中没有对应的4610. *,那么我需要删除它们。这是家常便饭,我想不通。我确实找到了一种创建无限循环的绝妙方法。我非常感谢您的帮助。谢谢。
我附上了到目前为止所做的所有代码。我正在尝试将此新过程放入DataMatch子目录中。这是我第一次搞不懂VBA,所以hmmmmmmmm很有趣。再次感谢。
Option Explicit
Sub CleanUpData()
'Prepare Excel for macro to run
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False
Call InitialDataClean
Call SecondDataScrub
Call DataMatch
'Call RemoveBlanks
'Return Excel to Status prior to Macro
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Sub DataMatch()
End Sub
Sub RemoveBlanks()
'Declare the variables
Dim deleteRow As Long
Dim ws As Worksheet
'Set Objects & declare known variables
Set ws = ActiveSheet
'Loop through the rows of data, in order to delete row matching desired variables
For deleteRow = ws.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
If ws.Range("A" & deleteRow).Text = "" Then
Rows(deleteRow).EntireRow.ClearFormats
Rows(deleteRow).EntireRow.Delete
End If
Next deleteRow
End Sub
Sub SecondDataScrub()
'Declare the variables
Dim deleteRow As Long
Dim ws As Worksheet
Dim myCriteria2 As String
Dim myCriteria3 As String
'Set Objects & declare known variables
Set ws = ActiveSheet
myCriteria2 = "*480*"
myCriteria3 = "*490*"
'Loop through the rows of data, in order to delete row matching desired variables
For deleteRow = ws.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
'Initial removal of unneeded data
If ws.Range("A" & deleteRow).Text Like myCriteria2 And ws.Range("b" & deleteRow).Value < 0 Then
Rows(deleteRow).EntireRow.Delete
End If
If ws.Range("A" & deleteRow).Text Like myCriteria3 And ws.Range("b" & deleteRow).Value < 0 Then
Rows(deleteRow).EntireRow.Delete
End If
Next deleteRow
End Sub
Sub InitialDataClean()
'Declare the variables
Dim deleteRow As Long
Dim ws As Worksheet
Dim myCriteria As String
Dim myCriteria2 As String
Dim myCriteria3 As String
'Set Objects & declare known variables
Set ws = ActiveSheet
myCriteria = "*4610.*"
myCriteria2 = "*4700.*"
myCriteria3 = "*4871.*"
'Loop through the rows of data, in order to delete row matching desired variables
For deleteRow = ws.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
'Initial removal of unneeded data
If ws.Range("A" & deleteRow).Text Like myCriteria And ws.Range("B" & deleteRow).Value >= 0 Then
Rows(deleteRow).EntireRow.Delete
End If
'If ws.Range("A" & deleteRow).Text = "" Then
'Rows(deleteRow).EntireRow.ClearFormats
'Rows(deleteRow).EntireRow.Delete
'End If
If ws.Range("A" & deleteRow).Text Like myCriteria2 Then
Rows(deleteRow).EntireRow.Delete
End If
If ws.Range("A" & deleteRow).Text Like myCriteria3 Then
Rows(deleteRow).EntireRow.Delete
End If
Next deleteRow
End Sub
[1]: https://i.stack.imgur.com/kgezp.png
答案 0 :(得分:0)
如果我对您的帖子正确无误,则您的逻辑是:
这种逻辑正确吗?可以按D列对行进行排序吗?还是必须保留顺序?