Excel精英培训网

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

[已解决]判断选择的是否是整行

[复制链接]
发表于 2010-5-5 13:39 | 显示全部楼层 |阅读模式

不知道是否有更好的方法?

这是我的,感觉绕弯了。

假设选择了1行,或者多行,或者部分单元格

on error resume next

a=replace(selection.address, "$","")

b=split(a, ":")(0)

c=split(a, ":")(1)

d=b*1+c*1

if err.number = 0 then

     msgbox "yes, you select one row or rows"

else

   msgbox "no, not a row"

end if

on error goto 0

最佳答案
2010-5-5 13:43
selection.address和selection.entirerow.address对比这样行么?
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2010-5-5 13:43 | 显示全部楼层    本楼为最佳答案   

selection.address和selection.entirerow.address对比这样行么?
回复

使用道具 举报

 楼主| 发表于 2010-5-5 13:48 | 显示全部楼层

QUOTE:
以下是引用小线在2010-5-5 13:43:00的发言:
selection.address和selection.entirerow.address对比这样行么?

是喔,小线这个的确可以的。谢谢哦,[em17][em17][em17]

看看还有其他的提议么?[em09]

回复

使用道具 举报

发表于 2010-5-5 13:50 | 显示全部楼层


Sub Test()
    If Selection.Address = Selection.EntireRow.Address Then
        MsgBox "Yes,you select one row  or rows"
    Else
        MsgBox "No,not a row"
    End If
End Sub
[此贴子已经被作者于2010-5-5 13:50:57编辑过]
回复

使用道具 举报

 楼主| 发表于 2010-5-5 13:54 | 显示全部楼层

QUOTE:
以下是引用小线在2010-5-5 13:50:00的发言:

Sub Test()
    If Selection.Address = Selection.EntireRow.Address Then
        MsgBox "Yes,you select one row  or rows"
    Else
        MsgBox "No,not a row"
    End
  If
End
  Sub

谢谢帮我验证了一次。这样的确可以的。[em23]

回复

使用道具 举报

发表于 2010-5-5 14:07 | 显示全部楼层

这样不知道对不对


Sub Test()
    With Selection
        If .Count / .Rows.Count = Rows(1).Columns.Count Then
            MsgBox "Yes , you select one row or rows"
        Else
            MsgBox "No , not a row"
        End If
    End With
End Sub
回复

使用道具 举报

 楼主| 发表于 2010-5-5 14:14 | 显示全部楼层

这个也行,不过还是刚才那个简单一些。谢谢,[em24]

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-28 06:02 , Processed in 0.323644 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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