列数据过滤器

桑迪

我有一列要过滤的数据,此过滤器有两个不同的组成部分。

步骤1:

  • 向下浏览一列数据
  • 找出数据块中的空白
  • 小于指定单元格值的间隙将填充为1

第2步:

  • 向下移动与步骤1相同的数据列
  • 标识由少于指定单元格值的行数组成的数据组
  • 小于指定单元格值的数据块将被删除

我已经创建了一个宏,该宏可以填充小于某个单元格值(Cells(1,15).Value)的数据组中的空白,如下所示。

这是到目前为止,我已经开始为第二步编写宏,但是无法克服语法错误。下面还显示了原始数据和已过滤数据的示例。

语法错误是一回事,我正在努力执行第二步,因此将不胜感激。

干杯

Option Explicit
Sub FillInTheBlanks()
'
' FillInTheBlanks Macro
'
'Declare integers and decimal characters

Dim iCol As Long, Last As Long, i As Long
    Dim iBlank As Long, BlankMode As Boolean, iCount As Long
    Dim j As Long, i1 As Long, iFullCount As Long 'Declare integers, boolean and decimal characters


    iCol = ActiveCell.Column 'Column identified by active cell
    Last = Cells(Rows.Count, iCol).End(xlUp).Row 'Determine end of nominated range
    iBlank = 0 'iBlank starts at zero
    iFullCount = 0 'iBlank starts at zero
    BlankMode = False 'BlankMode starts as False


    For i = 4 To Last 'Start at row 4 and go to the end of column
        If BlankMode Then  'If the next cell is empty

            If Cells(i, iCol) = "" Then
                iBlank = iBlank + 1 'If an emty cell is detected increase iBlank by 1
                iCount = iBlank 'Count the spaces

            Else
                  For j = i1 To i - 1 And iCount < Cells(1, 15).Value
                      Cells(j, iCol).Value = 1
                  Next j
                  BlankMode = False
            End If

        Else

            If Cells(i, iCol) = "" Then
                iBlank = 1
                i1 = i
                BlankMode = True
            End If

        End If
    Next i
End Sub

Option Explicit
Sub EraseSpikes()
'
'
'
'

Dim iCol As Long, Last As Long, i As Long
    Dim iFullCount As Long
    Dim p As Long


    iCol = ActiveCell.Column
    Last = Cells(Rows.Count, iCol).End(xlUp).Row

    iFullCount = 0



    For i = 4 To Last


            If Cells(i, iCol) = 1 Then
             iFullCount = iFullCount + 1
             p = i
            Else
                  If iFullCount < Cells(1, 15).Value And Sum(Range(Cells(p, iCol),Cells(p-Cells(1, 15).Value,iCol))=0 And Sum(Range(Cells(p+iFullCount, iCol),Cells(p+iFullCount(1, 15).Value,icol))=0

                  End If

            End If
    Next i
End Sub

1   1           1
2   1           1
3   1           1
4   1           1
5   1           1
6   1           1
7   1           1
8               
9               
10              
11              
12              
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24  1           1
25  1           1
26  1           1
27  1           1
28  1           1
29  1           1
30  1           1
31  1           1
32  1           1
33  1           1
34  1           1
35  1           1
36  1           1
37  1           1
38  1           1
39              1
40              1
41  1           1
42  1           1
43  1           1
44  1           1
45  1           1
46  1           1
47              1
48  1           1
49  1           1
50  1           1
51  1           1
52  1           1
53  1           1
54              1
55              1
56              1
57              1
58  1           1
59  1           1
60  1           1
61  1           1
62  1           1
63  1           1
64              1
65              1
66              1
67              1
68              1
69  1           1
70  1           1
71  1           1
72  1           1
73  1           1
74  1           1
75              1
76              1
77              1
78              1
79              1
80              1
81              1
82  1           1
83  1           1
84  1           1
85  1           1
86  1           1
87  1           1
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100             
101             
102             
103             
104             
105             
106             
107 1           
108 1           
109 1           
110 1           
111 1           
112 1           
113             
114             
115             
116             
117             
118             
119             
120             
121             
122             
123             
124             
125             
126             
127             
128             
129             
130             
131             
132             
133             
134             
135             
136             
137 1           1
138 1           1
139 1           1
140 1           1
141 1           1
142 1           1
143             1
144             1
145             1
146             1
147             1
148             1
149             1
150             1
151             1
152             1
153             1
154             1
155 1           1
156 1           1
157 1           1
158 1           1
159 1           1
160 1           1
强野

您的语法错误是与此行:

If iFullCount < Cells(1, 15).Value And Sum(Range(Cells(p, iCol),Cells(p-Cells(1, 15).Value,iCol))=0 And Sum(Range(Cells(p+iFullCount, iCol),Cells(p+iFullCount(1, 15).Value,icol))=0

分解:

Sum(Range(Cells(p, iCol),Cells(p-Cells(1, 15).Value,iCol))

您缺少方括号,并且Sum不是VBA功能。相反,您将使用Application.Sum

根据我认为您实际需要的内容,我编写的内容略有不同让我知道这是否适合您。

Sub EraseSpikes()
'
'
'
'

Dim iCol As Long, Last As Long, i As Long, j As Integer, startOfBlock As Integer

    startOfBlock = -1   'Initialise startOfBlock. -1 means we're not in a block yet


    iCol = ActiveCell.Column
    Last = Cells(Rows.Count, iCol).End(xlUp).Row

    For i = 4 To Last   'Begin loop from row 4 (?) to the end

            If Cells(i, iCol) = 1 Then          'If we find a 1...
                If startOfBlock = -1 Then       'And the block hasn't yet been started...
                    startOfBlock = i            'Mark this line as the start of our block
                End If
            Else                                'If we don't find a 1...
                If startOfBlock = -1 Then       'And we're not in a block...
                    GoTo nextLoop:              'We skip the rest of this until we're in a block
                End If
                If (i - startOfBlock) < Cells(1, 15).Value Then     'We didn't skip, so we're in a block.
                                                                    'we check if (current row number - start row number)
                                                                    'is less than the value in Cell(1,15) (Not equal to?)

                    For j = startOfBlock To i                       'It was, so we loop through all the rows in that block blanking them
                        Cells(j, iCol).Value = ""
                    Next j
                End If

                startOfBlock = -1                                   'Reset to not being in a block
            End If
nextLoop:
    Next i
End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ngGrid如何在多个列(例如Excel数据过滤器)上创建过滤器?

来自分类Dev

使用Jquery过滤器检查重复的列数据

来自分类Dev

根据过滤器更改数据框列的值

来自分类Dev

来自元组列表的数据框列过滤器

来自分类Dev

多列过滤器

来自分类Dev

如何过滤数据过滤器jQuery

来自分类Dev

angularJS过滤器未过滤数据

来自分类Dev

数据表与我在选择过滤器列过滤上的引导类混淆

来自分类Dev

如何使用为计算列指定的过滤器过滤剑道网格数据

来自分类Dev

Delphi ADO数据集过滤器

来自分类Dev

数据框过滤器提供NullPointerException

来自分类Dev

Spark数据框过滤器操作

来自分类Dev

pySpark数据框过滤器方法

来自分类Dev

Spark数据集过滤器元素

来自分类Dev

Django过滤器:计数数据

来自分类Dev

AWS Bucket过滤器下载数据

来自分类Dev

Spring数据Elasticsearch过滤器聚合

来自分类Dev

Pyspark多重过滤器数据框

来自分类Dev

Delphi ADO数据集过滤器

来自分类Dev

数据表单列过滤器

来自分类Dev

主数据透视表过滤器

来自分类Dev

Laravel多表数据过滤器

来自分类Dev

数据过滤器“从,到”角度

来自分类Dev

数据表过滤器删除

来自分类Dev

Linq 过滤器返回的数据重复

来自分类Dev

反应原生过滤器数据

来自分类Dev

Pyspark 数据框过滤器 OR 条件

来自分类Dev

数据框列上的 Savgol 过滤器

来自分类Dev

带列的HTML表过滤器