Excel精英培训网

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

[已解决]如何设置按TAB键后单元格跳转顺序

[复制链接]
发表于 2010-1-18 14:47 | 显示全部楼层 |阅读模式

如何设置按TAB键后单元格跳转顺序

如附件表中,按TAB键后按顺序跳转,哪位高手帮帮忙,写个代码呀,谢谢了

Ca0fRtIL.rar (1.35 KB, 下载次数: 27)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2010-1-18 14:58 | 显示全部楼层

要先执行设定Tab键,不用的时候可以取消。
Sub 自定义跳转()
    Dim Rng As Range, NextNum
    Set Rng = Range("A1:E12")
    NextNum = IIf(Selection = 9, 1, Selection + 1)
    Rng.Find(NextNum).Select
End Sub
Sub 设定Tab键()
    Application.OnKey "{TAB}", "自定义跳转"
End Sub
Sub 取消Tab键()
    Application.OnKey "{TAB}"
End Sub

回复

使用道具 举报

 楼主| 发表于 2010-1-18 15:07 | 显示全部楼层

我的意思是单元格里没有数字的时候也会按这个顺序跳转呀,你这个代码要是没有数字了就不会跳转呀,能不能帮我重新写一个,先谢谢了

回复

使用道具 举报

发表于 2010-1-18 15:12 | 显示全部楼层

你根据自己要求修改吧


Sub 自定义跳转()
    Dim NextNum, arrAddress
    NextNum = IIf(Selection = 9, 1, Selection + 1)
    '设定数组,放地址
    ReDim arrAddress(1 To 9)
    arrAddress(1) = "B2"
    arrAddress(2) = "B5"
    arrAddress(3) = "B8"
    arrAddress(4) = "D2"
    arrAddress(5) = "D4"
    arrAddress(6) = "D8"
    arrAddress(7) = "A11"
    arrAddress(8) = "C11"
    arrAddress(9) = "E12"
    Range(arrAddress(NextNum)).Select
End Sub
Sub 设定Tab键()
    Application.OnKey "{TAB}", "自定义跳转"
End Sub
Sub 取消Tab键()
    Application.OnKey "{TAB}"
End Sub

回复

使用道具 举报

 楼主| 发表于 2010-1-18 15:16 | 显示全部楼层

QUOTE:
以下是引用amulee在2010-1-18 15:12:00的发言:

你根据自己要求修改吧


Sub 自定义跳转()
    Dim NextNum, arrAddress
    NextNum = IIf(Selection = 9, 1, Selection + 1)
    '设定数组,放地址
    ReDim arrAddress(1 To 9)
    arrAddress(1) = "B2"
    arrAddress(2) = "B5"
    arrAddress(3) = "B8"
    arrAddress(4) = "D2"
    arrAddress(5) = "D4"
    arrAddress(6) = "D8"
    arrAddress(7) = "A11"
    arrAddress(8) = "C11"
    arrAddress(9) = "E12"
    Range(arrAddress(NextNum)).Select
End
   Sub
Sub 设定Tab键()
    Application.OnKey "{TAB}", "自定义跳转"
End
   Sub
Sub 取消Tab键()
    Application.OnKey "{TAB}"
End
   Sub

你这个好像不行呀

回复

使用道具 举报

发表于 2010-1-18 15:21 | 显示全部楼层

QUOTE:
以下是引用baiqghd在2010-1-18 15:16:00的发言:

你这个好像不行呀

由于Tab键是系统键,要先运行宏设定Tab键,然后再点击Tab试试看。

所有的代码要放在新建模块中。

回复

使用道具 举报

 楼主| 发表于 2010-1-18 15:30 | 显示全部楼层

QUOTE:
以下是引用amulee在2010-1-18 15:21:00的发言:

由于Tab键是系统键,要先运行宏设定Tab键,然后再点击Tab试试看。

所有的代码要放在新建模块中。

设置了,只会跳到B2单元格,接下来就不会跳了

回复

使用道具 举报

发表于 2010-1-18 15:40 | 显示全部楼层    本楼为最佳答案   

Sorry,代码如下:


Sub 自定义跳转()
    Dim NextNum, arrAddress
    NextNum = Selection.Address(0, 0)
    '设定数组,放地址
    ReDim arrAddress(1 To 9)
    arrAddress(1) = "B2"
    arrAddress(2) = "B5"
    arrAddress(3) = "B8"
    arrAddress(4) = "D2"
    arrAddress(5) = "D4"
    arrAddress(6) = "D8"
    arrAddress(7) = "A11"
    arrAddress(8) = "C11"
    arrAddress(9) = "E12"
    For i = 1 To 9
        If arrAddress(i) = NextNum Then
            NextNum = IIf(i = 9, 1, i + 1)
            Exit For
        End If
        If i = 9 Then NextNum = 1
    Next
    Range(arrAddress(NextNum)).Select
End Sub
Sub 设定Tab键()
    Application.OnKey "{TAB}", "自定义跳转"
End Sub
Sub 取消Tab键()
    Application.OnKey "{TAB}"
End Sub
回复

使用道具 举报

 楼主| 发表于 2010-1-18 15:44 | 显示全部楼层

成功了,厉害呀,真是太感谢了,[em17][em17][em17]
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-16 22:55 , Processed in 0.295632 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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