excel - 选择范围的问题可能是因为最后一列和最后一行设置不正确
问题描述
我正在尝试选择范围并为所有颜色单元格粘贴 0。
我不明白为什么这段代码不起作用。我浏览了论坛中的几个选项,但仍然无法正常工作。我很确定这与最后一行和最后一列有关,这是显而易见的。
你能告诉我我在这里做错了什么吗?
Dim cell As Range, rng As Range
Dim LRRow As Long, LRCol As Long
With ThisWorkbook.Worksheets("Data")
LRRow = .Cells(4, .Columns.Count).End(xlToLeft).Column
LRCol = .Cells(.Rows.Count, LRRow).End(xlUp).row
Set rng = .Range(Cells(7, 4), Cells(LRRow, LRCol))
' Selection.AutoFilter
' Range("A1").Select
For Each cell In rng
If cell.Interior.Color = RGB(255, 204, 204) And cell.Value = "" Then
cell.Value = 0
End If
Next cell
End With
解决方案
尝试改变:
LRRow = .Cells(4, .Columns.Count).End(xlToLeft).Column
LRCol = .Cells(.Rows.Count, LRRow).End(xlUp).row
至
LRRow = .Cells(.Rows.Count, LRRow).End(xlUp).row
LRCol = .Cells(4, .Columns.Count).End(xlToLeft).Column
推荐阅读
- php - 这个搜索系统是否容易受到 SQL 注入的影响?
- reactjs - FullCalendar 用于创建事件的新约会按钮
- python - pyenv+pipx引起的Jupyter内核问题
- python - 横幅抓取错误:HTTP/1.0 408 Request Time-out python socket 编程
- xquery - Functx 模块和带有字符结尾的长字符串
- c++ - 指向成员函数类类型的指针
- sql - 子查询 - 关键字“声明”附近的语法不正确
- regex - 正则表达式不仅适用于空格
- r - R 是否有 += 和 -= 运算符的实现?
- reactjs - npm 包的实际重量是多少?