【发布时间】:2018-04-07 03:57:38
【问题描述】:
我正在尝试使用 VBA 按列的值过滤表,然后在工作表上输出一个新表(已过滤),但是一个新区域。注意我想单元格引用范围号。
在下面的假excel表上。我想过滤“年龄”列的范围。 IE。过滤器 --> 年龄 --> 1-3 之间(单元格参考)。第一个表是原始数据。其次是我想使用 VBA 作为输出。
我尝试将下面的代码拟合到我想要的输出。它缺少与列本身无关的数据(取整列)
Excel VBA, How to select rows based on data in a column?
Option Explicit
Sub tablefilter()
Dim lastRow As Long, x As Long
Dim lasColumn As Long, i = 4
Dim CopyRange As Range
With Sheets("Sheet1")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For x = 1 To lastRow
If Len(Trim(.Range("A" & x).Value)) 1<3 Then
If CopyRange Is Nothing Then
Set CopyRange = .Rows(i)
Else
Set CopyRange = Union(CopyRange, .Rows(x))
End If
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Sheets("Sheet2").Rows(1)
End If
End With
【问题讨论】:
-
我不太确定你在这里问什么...请参考how-to-ask。如果您需要代码方面的帮助,我们非常愿意为您提供帮助,但是我们不提供代码
-
行
If Len(Trim(.Range("A" & x).Value)) 1<3 Then包含语法错误。您是否正在寻找文本长度小于 3 的行?如果是这样,请尝试If Len(Trim(.Range("A" & x).Value)) < 3 Then。