Excel精英培训网

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

[已解决]求助,请高手帮忙修改代码

[复制链接]
发表于 2011-11-6 01:42 | 显示全部楼层 |阅读模式
求助,请高手帮忙修改代码在此谢谢
最佳答案
2011-11-6 08:14
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Address = "$C$2" Then
  3. Cells.EntireRow.Hidden = 0
  4. t = [d2]
  5. y = [e2]
  6. x = Range("a65536").End(3).Row
  7. If Not Range("a:a").Find(Target, , , 1) Is Nothing Then
  8.     Rows("3:" & t - 1).EntireRow.Hidden = 1
  9.     Rows(y + 1 & ":" & x).EntireRow.Hidden = 1
  10. Else
  11.     Cells.EntireRow.Hidden = 0
  12. End If
  13. End If
  14. End Sub
复制代码

新建 Microsoft Excel 工作表.rar

13.91 KB, 下载次数: 13

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-11-6 08:14 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Address = "$C$2" Then
  3. Cells.EntireRow.Hidden = 0
  4. t = [d2]
  5. y = [e2]
  6. x = Range("a65536").End(3).Row
  7. If Not Range("a:a").Find(Target, , , 1) Is Nothing Then
  8.     Rows("3:" & t - 1).EntireRow.Hidden = 1
  9.     Rows(y + 1 & ":" & x).EntireRow.Hidden = 1
  10. Else
  11.     Cells.EntireRow.Hidden = 0
  12. End If
  13. End If
  14. End Sub
复制代码
回复

使用道具 举报

发表于 2011-11-6 11:33 | 显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
application.ScreenUpdating=False
If Target = Range("c2") Then
  Dim LastRow, i As Integer
  
  
  LastRow = Range("a65535").End(xlUp).Row
  Debug.Print LastRow
  

  For i = 1 To LastRow
   
   Select Case Target.Value
    Case Is = 1
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 1 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 2
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 2 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 3
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 3 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 4
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 4 Then
     Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 5
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 5 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 6
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 6 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 7
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 7 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 8
     Cells.EntireRow.Hidden = False
     If Cells(i + 3, 1).Value <> 8 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
   End Select
  Next
End If
application.ScreenUpdating=true
End Sub

我只列出8个其他你自己做
回复

使用道具 举报

发表于 2011-11-6 11:37 | 显示全部楼层
有点小错误,更正如下:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target = Range("c2") Then
  Dim LastRow, i As Integer
  
  
  LastRow = Range("a65535").End(xlUp).Row
  Debug.Print LastRow
  Cells.EntireRow.Hidden = False

  For i = 1 To LastRow
   
   Select Case Target.Value
    Case Is = 1
     If Cells(i + 3, 1).Value <> 1 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 2
     If Cells(i + 3, 1).Value <> 2 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 3
     If Cells(i + 3, 1).Value <> 3 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 4
     If Cells(i + 3, 1).Value <> 4 Then
     Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 5
     If Cells(i + 3, 1).Value <> 5 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 6
     If Cells(i + 3, 1).Value <> 6 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 7
     If Cells(i + 3, 1).Value <> 7 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
    Case Is = 8
     If Cells(i + 3, 1).Value <> 8 Then
      Cells(i + 3, 1).EntireRow.Hidden = True
     End If
   End Select
  Next
End If
End Sub
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 02:48 , Processed in 0.237377 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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