Excel精英培训网

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

[已解决]求修改代码(查找定位)

[复制链接]
发表于 2017-7-18 08:49 | 显示全部楼层 |阅读模式
请看附件~~~~~~谢谢
最佳答案
2017-7-18 09:00
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim A As Range
  3.     Dim C As Date
  4.     Application.EnableEvents = False
  5.     With Target
  6.         If .Address = "$N$2" Then
  7.             Set A = [B:B].Find(what:=.Value, LookAt:=xlWhole)
  8.             If Not A Is Nothing Then
  9.                 Range("B" & A.Row).Select
  10.             Else
  11.                 MsgBox "没有找到数据!"
  12.                 [N2].ClearContents
  13.                 [N2].Select
  14.             End If
  15.         
  16.         End If
  17.     End With
  18.     Application.EnableEvents = True
  19. End Sub
复制代码

日期查找.rar

13.68 KB, 下载次数: 13

发表于 2017-7-18 09:00 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim A As Range
  3.     Dim C As Date
  4.     Application.EnableEvents = False
  5.     With Target
  6.         If .Address = "$N$2" Then
  7.             Set A = [B:B].Find(what:=.Value, LookAt:=xlWhole)
  8.             If Not A Is Nothing Then
  9.                 Range("B" & A.Row).Select
  10.             Else
  11.                 MsgBox "没有找到数据!"
  12.                 [N2].ClearContents
  13.                 [N2].Select
  14.             End If
  15.         
  16.         End If
  17.     End With
  18.     Application.EnableEvents = True
  19. End Sub
复制代码

评分

参与人数 1 +1 收起 理由
171774040 + 1 赞一个

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2017-7-18 09:12 | 显示全部楼层

可否把代码由原来的跳转到B列某一单元格,改为跳转到B列所在的行?
回复

使用道具 举报

发表于 2017-7-18 10:10 | 显示全部楼层
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim A As Range
  3.     Dim C As Date
  4.     Application.EnableEvents = False
  5.     With Target
  6.         If .Address = "$N$2" Then
  7.             Set A = [B:B].Find(what:=.Value, LookAt:=xlWhole)
  8.             If Not A Is Nothing Then
  9.                Rows(A.Row).Select
  10.             Else
  11.                 MsgBox "没有找到数据!"
  12.                 [N2].ClearContents
  13.                 [N2].Select
  14.             End If
  15.         
  16.         End If
  17.     End With
  18.     Application.EnableEvents = True
  19. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2017-7-31 21:45 来自手机 | 显示全部楼层
本帖最后由 171774040 于 2017-7-31 21:47 编辑

[size=37.7999992370606px]谢谢……
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 06:39 , Processed in 0.292548 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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