Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 6986|回复: 4

[已解决]如何 选中区域中 不特定 的 所有非空单元格 所在的行

[复制链接]
发表于 2013-7-16 18:01 | 显示全部楼层 |阅读模式
sub t()
Dim ee As Integer
Dim ff As Integer

ee = Sheets("意向金台账").Range("B65536").End(xlUp).Row
For ff = 3 To ee
If Sheets("意向金台账").Range("k" & ff) <> "" Then
Sheets("意向金台账").Range("k" & ff).EntireRow.Select
  End If
Next ff

end if
End Sub

用以上的代码只能选中 最后一个 非空单元格  所在的行,帮忙看如何修改。
最佳答案
2013-7-16 22:41
sub t()
Dim ee As Integer
Dim ff As Integer
Dim rSelect as Range

ee = Sheets("意向金台账").Range("B65536").End(xlUp).Row
For ff = 3 To ee
    If Sheets("意向金台账").Range("k" & ff) <> "" Then
        If rSelect Is Nothing Then
             Set rSelect = Sheets("意向金台账").Rows(ff)
        Else
             Set rSelect = Union(rSelect, Sheets("意向金台账").Rows(ff))
        End If
    End If
Next ff
rSelect.Select
End Sub
发表于 2013-7-16 18:47 | 显示全部楼层
循环完了肯定只能选择最后一个嘛。在循环过程中选择非空后又选择了下一个非空的。最后你看到的肯定是只有一个的。
回复

使用道具 举报

 楼主| 发表于 2013-7-16 19:04 | 显示全部楼层
回复

使用道具 举报

发表于 2013-7-16 22:41 | 显示全部楼层    本楼为最佳答案   
sub t()
Dim ee As Integer
Dim ff As Integer
Dim rSelect as Range

ee = Sheets("意向金台账").Range("B65536").End(xlUp).Row
For ff = 3 To ee
    If Sheets("意向金台账").Range("k" & ff) <> "" Then
        If rSelect Is Nothing Then
             Set rSelect = Sheets("意向金台账").Rows(ff)
        Else
             Set rSelect = Union(rSelect, Sheets("意向金台账").Rows(ff))
        End If
    End If
Next ff
rSelect.Select
End Sub
回复

使用道具 举报

 楼主| 发表于 2013-7-17 15:47 | 显示全部楼层
adders 发表于 2013-7-16 22:41
sub t()
Dim ee As Integer
Dim ff As Integer

谢谢指点!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-3 04:53 , Processed in 0.177516 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表