excel - 对过滤的单元格使用工作表函数 countif
问题描述
我正在使用下面的代码循环通过过滤列,并在循环时收集销售人员的每个姓名;我正在使用 SpecialCells(xlCellTypeVisible),它只拾取可见的行。我只想要名称一次,所以我使用 countif 工作表函数。获得名称后,我会将其存储在临时变量 (namelist_tmp) 中并添加分号。最终的游戏是创建一个变量(名称列表),每个名称用分号分隔,这样我就可以在我拥有的一些电子邮件代码的 .to 部分中使用它。
我能够遍历并捕获名称,但是当我尝试将临时变量分配给最终变量时,我在 namelist_tmp 代码处收到运行时错误 5 Invalid Procedure call or argument:
namelist = Left(namelist_tmp, Len(namelist_tmp) - 2)
我不确定我是否以正确的方式前进,善良的灵魂可以帮助我看到我的方式的错误吗?
Sub filteredstuff()
Dim lastRow As Long, myrange As Range
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
For Each myrange In Range("E11:E" & lastRow).SpecialCells(xlCellTypeVisible)
'At each name, use COUNTIF to look upwards and see if the name already exists.
'If not, add name, semi-colon and space to temporary name list
If WorksheetFunction.CountIf(Range("E11:E" & myrange.Row), _
Range("E" & myrange.Row)) < 2 Then
namelist_tmp = namelist_tmp & Range("E" & myrange.Row).Value & "; "
End If
'Strip last semi-colon & space off of temp list
namelist = Left(namelist_tmp, Len(namelist_tmp) - 2)
Next myrange
MsgBox namelist
End Sub
解决方案
我已经在虚拟数据上运行了您的代码,对我来说它有效,我没有收到任何错误。而且这条线很完美,应该没问题:
namelist = Left(namelist_tmp, Len(namelist_tmp) - 2)
你能提供更多细节吗?
推荐阅读
- java - 套接字 Python(服务器)到 Java(客户端)连接 Java 无法从主机接收数据
- sails.js - 无法从sails.js 编辑表单
- mysql - CakePHP 3中关于belongsToMany关联的问题
- batch-file - 如何在命令提示符中转义“&”和号
- maven - 我在哪里可以找到 IntelliJ IDEA 2018.1 CE 中的“添加框架支持”选项?
- c# - 在 SFML 库 c# 上使用密钥释放
- python - 如何在 processing.py 中的模块之间共享全局变量?
- python - python将交互数据合并成一行
- c++ - 在 for 循环中使用 erase() 仅擦除第一行
- laravel - 在 Laravel 项目中同步标签时出错