[英]selecting SpecialCells(xlCellTypeVisible) from specific columns of ListObject table
I am trying to get only the visible cells of certain columns of a ListObject table into a range object.我试图仅将 ListObject 表的某些列的可见单元格放入范围对象中。
This doesn't seem to work.这似乎不起作用。
dim rng as range
with activesheet.listobjects("Tab_data").databodyrange
set rng=.specialcells(xlcelltypevisible)
end with
but this works when i select entire range then offset 1st column to select the other 2 required columns!但是当我选择整个范围然后偏移第一列以选择其他 2 个必需的列时,这是有效的!
dim rng as range
with activesheet.usedrange
Set rng = .Offset(1, 1).Resize(.Rows.Count-1, .Columns.Count-1).SpecialCells(xlCellTypeVisible)
end with
but i cannot use the above in a formula as my formula is referring to only the 2 columns in the listobject shown below:但我不能在公式中使用上述内容,因为我的公式仅指列表对象中的 2 列,如下所示:
UDF Formula on worksheet:工作表上的 UDF 公式:
=TagCloud(RngWrdLst as Range)
and i am using it as:我将它用作:
=TagCloud(tab_data[[Brands]:[Index]])
As you can see from the image, i only want the visible cell ranges from columns "Brands" & "Index" and not the cells from "COLUMN" column.正如您从图像中看到的,我只想要“品牌”和“索引”列中的可见单元格范围,而不是“COLUMN”列中的单元格。
so the visible ranges i would like to have are:所以我想要的可见范围是:
"$B$2:$C$3,$B$45:$C$45,$B$75:$C$78"
If i have a UDF function being called from a worksheet cell and passed a ListObject range of columns B & C (only these columns and not entire databodyrange), then how am i going to find the RngWrdLst visible range?如果我有一个从工作表单元格调用的 UDF 函数并传递了列 B 和 C 的 ListObject 范围(仅这些列而不是整个数据体范围),那么我将如何找到 RngWrdLst 可见范围?
eg例如
call from worksheet:从工作表调用:
=TagCloud(tab_data[[Brands]:[Index]])
Function definition:函数定义:
Function TagCloud(RngWrdLst As Range)
Dim VisibleRng As Range
With RngWrdLst
Set VisibleRng = Intersect(.SpecialCells(xlCellTypeVisible), Union(.Columns(2), .Columns(3)))
Debug.Print VisibleRng.Address(0, 0)
End With
' do something with the visibleRng......
End Function
BTW, RngWrdLst would contain the 2 columns B & C. So how do i modify your code and get only the visible range from the function?顺便说一句,RngWrdLst 将包含 2 列 B 和 C。那么我如何修改您的代码并仅从函数中获取可见范围?
Use the Intersect method on a Union method of the columns you want.对所需列的 联合方法使用Intersect 方法。
Dim rng As Range
With ActiveSheet.ListObjects("Tab_data").DataBodyRange
Set rng = Intersect(.SpecialCells(xlCellTypeVisible), _
Union(.Columns(2), .Columns(3)))
Debug.Print rng.Address(0, 0)
End With
Alternately, shift right off the first column and resize one column less than the .DataBodyRange property contains.或者,右移第一列并调整比.DataBodyRange 属性包含的少一列的大小。
Dim rng As Range
With ActiveSheet.ListObjects("Tab_data").DataBodyRange
With .Resize(.Rows.Count, .Columns.Count - 1).Offset(0, 1)
Set rng = .SpecialCells(xlCellTypeVisible)
End With
Debug.Print rng.Address(0, 0)
End With
Depending upon what you wnt to do with rng
, you may have to loop through the Range.Areas property .根据您不打算使用
rng
做什么,您可能必须遍历Range.Areas 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.